2014-11-24 71 views
0

我使用Android的引導庫,它可以找到here。我已經將庫導入到我的應用程序中,但是問題是,按鈕不能覆蓋整個屏幕寬度。 我試着將按鈕並排放置並使用android:layout_weight="1",但按鈕​​只是向左移動而不伸展。我甚至嘗試使用android:layout_width="match_parent",但也增加了按鈕高度。Android的按鈕不拉伸到屏幕的寬度

This is how my layout looks with the library

是,如果我設置發生了什麼android:layout_width="0dip"android:layout_weight="1"(用於確定/取消)和android:layout_width="match_parent"(用於複選按鈕)

enter image description here

XML代碼

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

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="318dp" 
    android:layout_height="wrap_content" 
    android:text="Send Pin To Email id." 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Enter Your Email Id Below" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<com.beardedhen.androidbootstrap.BootstrapEditText 
    android:id="@+id/et_email" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:ems="10" 
    android:hint="[email protected]" 
    android:inputType="textEmailAddress" 
    bootstrapbutton:be_roundedCorners="true" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:paddingBottom="15sp" > 

    <com.beardedhen.androidbootstrap.BootstrapButton 
     android:id="@+id/OK" 
     style="@style/AppBaseTheme" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     android:text="OK" 
     bootstrapbutton:bb_icon_left="fa-envelope" 
     bootstrapbutton:bb_roundedCorners="true" 
     bootstrapbutton:bb_size="medium" 
     bootstrapbutton:bb_type="default" /> 

    <com.beardedhen.androidbootstrap.BootstrapButton 
     android:id="@+id/cancel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="10dp" 
     android:text="CANCEL" 
     bootstrapbutton:bb_icon_left="fa-times" 
     bootstrapbutton:bb_roundedCorners="true" 
     bootstrapbutton:bb_size="medium" 
     bootstrapbutton:bb_type="default" /> 
</LinearLayout> 

<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="@android:color/darker_gray" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="15sp" 

    android:text="Got your Pin?Enter it below." 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<com.beardedhen.androidbootstrap.BootstrapEditText 
    android:id="@+id/et_pin" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:ems="10" 
    android:hint="XXXX" 
    android:inputType="number" 
    bootstrapbutton:be_roundedCorners="true" /> 

<com.beardedhen.androidbootstrap.BootstrapButton 
    android:id="@+id/b_check" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_margin="10dp" 
    android:text="Check" 
    bootstrapbutton:bb_icon_left="fa-check" 
    bootstrapbutton:bb_roundedCorners="true" 
    bootstrapbutton:bb_size="medium" 
    bootstrapbutton:bb_type="default" /> 

</LinearLayout> 
+0

你需要被拉伸嗎?確定/取消或檢查? – 2014-11-24 09:13:17

+0

@androidKiller實際上他們..我想'確定/取消'並排(即相同的大小和填充寬度)​​和'檢查'來填補屏幕的寬度。 – 2014-11-24 09:15:07

+0

嘗試使用dp作爲填充和邊距,而不是主要用於文本大小的sp。 – 2014-11-24 09:32:11

回答

1

您需要使用寬度代替0dipwrap_content如果你使用weight屬性。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:paddingBottom="15sp" 
    android:weightSum="2"> 
    <com.beardedhen.androidbootstrap.BootstrapButton 
     android:id="@+id/OK" 
     style="@style/AppBaseTheme" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     android:text="OK" 
     bootstrapbutton:bb_icon_left="fa-envelope" 
     bootstrapbutton:bb_roundedCorners="true" 
     bootstrapbutton:bb_size="medium" 
     bootstrapbutton:bb_type="default" 
     android:layout_weight="1"/> 

    <com.beardedhen.androidbootstrap.BootstrapButton 
     android:id="@+id/cancel" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="10dp" 
     android:text="CANCEL" 
     bootstrapbutton:bb_icon_left="fa-times" 
     bootstrapbutton:bb_roundedCorners="true" 
     bootstrapbutton:bb_size="medium" 
     bootstrapbutton:bb_type="default" 
     android:layout_weight="1"/> 

而對於單個按鈕,只需使用寬度爲 「match_parent」

<com.beardedhen.androidbootstrap.BootstrapButton 
    android:id="@+id/b_check" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_margin="10dp" 
    android:text="Check" 
    bootstrapbutton:bb_icon_left="fa-check" 
    bootstrapbutton:bb_roundedCorners="true" 
    bootstrapbutton:bb_size="medium" 
    bootstrapbutton:bb_type="default" /> 

希望這有助於。

+0

它沒有工作..ive添加上面的屏幕截圖當我添加您的代碼 – 2014-11-24 09:28:50

+1

@Mike謝謝:)更正 – 2014-11-24 09:35:05

+0

@MysticMagic我認爲它是一個圖書館本身的問題。我知道你的代碼對於一個普通的按鈕來說是完美的,所以我會把這個標記爲正確的答案。 – 2014-11-25 07:12:08