2017-09-20 37 views
-5

我有這樣的佈局,一個對話框內:當使用重量的LinearLayout和3個按鈕,中間按鈕是有點低

<?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.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/rView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/button2" 
    android:layout_marginBottom="10dp"/> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentBottom="true" 
    android:text="" 
    android:background="@android:color/transparent" 
    android:clickable="false" 
    android:enabled="false"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:orientation="horizontal" 
    android:layout_below="@+id/rView" 
    android:weightSum="3"> 

    <Button 
     android:id="@+id/okbutton" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/ok" 
     android:background="@drawable/buttonshape" 
     android:layout_weight="1" 
     android:textColor="@color/blanco"/> 

    <Button 
     android:id="@+id/markall" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/checkall" 
     android:background="@drawable/buttonshape" 
     android:layout_weight="1" 
     android:textColor="@color/blanco"/> 

    <Button 
     android:id="@+id/cancelbutton" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/cancel" 
     android:background="@drawable/buttonshape" 
     android:layout_weight="1" 
     android:textColor="@color/blanco"/> 
</LinearLayout> 

這是我使用作爲背景被拉伸:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
<corners 
    android:radius="50dp" 
    /> 
<solid 
    android:color="@color/botones" 
    /> 
<stroke 
    android:width="0dp" 
    android:color="#878787" 
    /> 

中的LinearLayout裏面有3個按鍵,你可以看到。他們每個人都應該在線性佈局中使用相同數量的空間,而且他們實際上是這樣做的,但中央按鈕(markall)與其他人不一致,有點低,就像5dp或類似的東西。我不知道爲什麼會發生這種情況,以及如何解決這個問題。

任何幫助?

謝謝。

+0

我認爲它的做工精細的外觀截圖:HTTP:// prntscr。 com/gnf4vn –

+0

是的,我知道它應該工作,但不適合我。 – Fustigador

+1

你不能使用_wrap_content_,因爲你使用的是重量 – Piyush

回答

1

更改按鈕寬度「match_parent」。

+0

不好運,抱歉... – Fustigador

+0

你不能使用'match_parent',因爲OP正在使用'weight' – Piyush

+0

把它改成wrap_content並且解決了。謝謝,你把我放在正確的道路上。 – Fustigador

0

試試這個。

android:layout_height="match_parent"設置爲Button

並將android:gravity="center"設置爲Button文本。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_below="@+id/rView" 
    android:orientation="horizontal" 
    android:weightSum="3"> 

    <Button 
     android:id="@+id/okbutton" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@drawable/buttonshape" 
     android:gravity="center" 
     android:text="@string/ok" 
     android:textColor="@color/blanco"/> 

    <Button 
     android:id="@+id/markall" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@drawable/buttonshape" 
     android:gravity="center" 
     android:text="@string/checkall" 
     android:textColor="@color/blanco"/> 

    <Button 
     android:id="@+id/cancelbutton" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@drawable/buttonshape" 
     android:gravity="center" 
     android:text="@string/cancel" 
     android:textColor="@color/blanco"/> 
</LinearLayout> 
0

嘗試要麼改變了android:layout_height = 「match_parent」 到 「WRAP_CONTENT」, OR 每個按鈕的高度,以 「match_parent」

相關問題