2014-10-28 740 views
1

我正在使用linearlayout作爲父級,並在它內部我有兩個子線性佈局。我想在最後的LinearLayout按鈕對齊按鈕的屏幕的屏幕底部邊緣的底部應與主linearlayouts底邊距如何在LinearLayout中的屏幕底部對齊按鈕

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

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/parentlayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:orientation="vertical" > 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="bottom" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/save" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Save" /> 

    <Button 
     android:id="@+id/submit" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Submit" /> 

    <Button 
     android:id="@+id/cancel" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Cancel" /> 

    <Button 
     android:id="@+id/delete" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Delete" /> 

    <Button 
     android:id="@+id/reset" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Reset" /> 
    </LinearLayout> 
</LinearLayout> 
+0

我不知道什麼是你的問題呢,我把我們的代碼,並查看它在Eclipse和按鈕已經在屏幕的底部對齊了 – 2014-10-28 07:58:00

回答

1

只是減少按鈕文本的textsize。由於無法在一行中顯示文本,所以頁邊空白變形。

我在這裏取得了TEXTSIZE到11dp每個buttontext和視圖是完美的NexusOne尺寸顯示

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

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:id="@+id/parentlayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:orientation="vertical" > 
     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/buttons" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/save" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Save" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/submit" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Submit" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/cancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Cancel" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/delete" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Delete" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/reset" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Reset" 
      android:textSize="11dp" /> 
    </LinearLayout> 

</LinearLayout> 
+0

是的,這對我也很有用。但我懷疑它會工作,如果在id = parentlayout增加的數據會按鈕與textviews/edittexts重疊? – user3706655 2014-10-28 08:33:32

+0

它會工作,因爲主要的xml佈局是一個'LinearLayout'。較低線性佈局中的「按鈕」將簡單地停留在那裏。無論你在'id = parentlayout'中添加什麼,它都會進入'scrollview',如果你願意的話,我可以通過在'parentlayout'中添加一些元素來顯示一個例子。 – 2014-10-28 08:39:36

+1

是它的工作完美 – user3706655 2014-10-28 08:39:56

1

試試這個使用你的父母爲RelativeLayout的

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/parentlayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:orientation="vertical" > 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_gravity="bottom" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/save" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Save" /> 

    <Button 
     android:id="@+id/submit" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Submit" /> 

    <Button 
     android:id="@+id/cancel" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Cancel" /> 

    <Button 
     android:id="@+id/delete" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Delete" /> 

    <Button 
     android:id="@+id/reset" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Reset" /> 
</LinearLayout> 

+0

我已經在TableLayout中使用了與以前完美結合的相關佈局,但現在我想讓它與LinearLayout一起工作 – user3706655 2014-10-28 08:01:27

0
<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <LinearLayout 
       android:id="@+id/parentlayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="top" 
       android:orientation="vertical" > 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="bottom" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:id="@+id/buttons" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="bottom" 
       android:orientation="horizontal" > 

       <Button 
        android:id="@+id/save" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Save" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/submit" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Submit" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/cancel" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Cancel" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/delete" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Delete" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/reset" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Reset" 
        android:textSize="12sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </FrameLayout> 
</FrameLayout> 

+0

嘿,謝謝,這對我來說非常合適。但是爲什麼我們應該使用按鈕的線性佈局樹?還請讓我知道如果android:id =「@ + id/parentlayout」中的數據列表增加,文本會與按鈕重疊嗎? – user3706655 2014-10-28 08:16:23

1

如果您使用RelativeLayout來滿足這種要求,它會更好。將工作沒有麻煩。

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

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 

<LinearLayout 
    android:id="@+id/parentlayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:orientation="vertical" > 
</LinearLayout> 
</ScrollView> 

<LinearLayout 
android:id="@+id/buttons" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="bottom" 
android:layout_alignParentBottom="true" 
android:orientation="horizontal" > 

<Button 
    android:id="@+id/save" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Save" /> 

<Button 
    android:id="@+id/submit" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Submit" /> 

<Button 
    android:id="@+id/cancel" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Cancel" /> 

<Button 
    android:id="@+id/delete" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Delete" /> 

<Button 
    android:id="@+id/reset" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Reset" /> 
</LinearLayout> 
</RelativeLayout>