2014-09-03 112 views
0

我有我的佈局問題,這是我的佈局代碼:Android的佈局工作不正常

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <ScrollView 
      android:id="@+id/Scroll" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TableLayout 
       android:id="@+id/Table" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

      </TableLayout> 
     </ScrollView> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="fill_parent" 

     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <ImageView 
      android:id="@+id/BookingStatus" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/BookingBtn" 
      android:src="@drawable/statusbarcomplete"/> 

     <Button 
      android:id="@+id/BookingBtn" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="@color/Red" 
      android:text="Place My Booking" 
      android:textAllCaps="true" 
      android:textColor="@color/White" 
      android:textStyle="bold"/> 
    </RelativeLayout> 

</RelativeLayout> 

這裏是如何看起來小設備上: Small Device

這裏它是如何看起來在一個大型設備上 Big Device

現在,你可以看到問題是與小設備,按鈕和圖像似乎「漂浮」在佈局的頂部,而我希望他們在buttom的在任何時候的佈局。因此,用戶需要在小型設備上滾動,但底部的圖像和按鈕始終處於底部並始終可見!滾動視圖將佔用屏幕的其餘部分,以便用戶可以看到信息。

您可以查看XML文件here完整的代碼。我刪除了所有的表格,以保持這個線程整潔,因爲代碼是超過300行

+0

您可以滾動視圖分配佈局,高度值... – micky 2014-09-03 10:16:54

+0

你需要遵循http://developer.android.com/training/multiscreen/screensizes.html和我在我的情況做了我犯了一個具體的佈局-mdpi,layout-xhdpi等res中和運行時的特定目錄,佈局將根據屏幕的大小顯示。注意*僅將那些受到干擾的佈局添加到這些目錄 – 2014-09-03 10:21:53

+0

佈局-height永遠不會工作,它只會對特定的分辨率有用嗎? – apmartin1991 2014-09-03 10:23:04

回答

1
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" > 



     <ScrollView 
      android:id="@+id/Scroll" 
      android:layout_above="@+id/relative" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:paddingBottom="10dp" 
      android:orientation="vertical" > 

      <TableLayout 
       android:id="@+id/Table" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </TableLayout> 
     </ScrollView> 

    <LinearLayout 
     android:id="@+id/relative" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentBottom="true" > 

     <ImageView 
      android:id="@+id/BookingStatus" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/BookingBtn" /> 

     <Button 
      android:id="@+id/BookingBtn" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:padding="10dp" 
      android:background="@color/Red" 
      android:text="Place My Booking" 
      android:textAllCaps="true" 
      android:textColor="@color/White" 
      android:textStyle="bold" /> 
    </LinearLayout> 

</RelativeLayout> 

試試這個。只需將滾動視圖放在包含圖像和按鈕的相對佈局上方即可。

+0

似乎已經完成了這個訣竅,讓我測試一個小的和一個大的設備,我會回到你身邊,如果它能正常工作,它將被標記爲正確。 – apmartin1991 2014-09-03 10:35:58

+0

標記爲正確,非常感謝 – apmartin1991 2014-09-03 10:38:28

+0

@ apmartin1991只要您的底部內容適合該10dp填充內容,此答案就會生效。 – Luksprog 2014-09-03 10:43:18

0

試試這個.. 把它放在最後RelativeLayout。

機器人:layout_gravity = 「底」