2013-09-18 3 views
0

Вот скриншот моего мобильного приложения. Как я могу настроить кнопку «Управление категориями» в центре внизу, потому что это черное пространство внизу не кажется хорошим.Настройка макета Android

enter image description here

Вот мой файл макета.

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

    <ListView 
     android:id="@+id/listCategory" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="0.9" 
     android:background="#FFFFFF" 
     android:gravity="top" /> 

    <Button 
     android:id="@+id/btnManageCategory" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:onClick="onButtonClick" 
     android:text="Manage Category" 
     android:gravity="center" 
     /> 

</LinearLayout> 
+0

ли вы попробовать установить высоту вашего 'LinearLayout' в wrap_content? – ClaireG

ответ

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

    <ListView 
     android:id="@+id/listCategory" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:background="#FFFFFF" 
     android:gravity="top" /> 
    <View 
     android:id="@+id/view" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1"> 
    </View> 

    <Button 
     android:id="@+id/btnManageCategory" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:onClick="onButtonClick" 
     android:text="Manage Category" 
     android:gravity="center" 


     /> 

</LinearLayout> 
0

Попробуйте это:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_root" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

<ListView 
    android:id="@+id/listCategory" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="0.9" 
    android:background="#FFFFFF" 
    android:gravity="top" /> 

<Button 
    android:id="@+id/btnManageCategory" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:onClick="onButtonClick" 
    android:text="Manage Category" 
    android:gravity="center" 
    /> 

</LinearLayout> 
0

Вы можете попробовать использовать weights. Возможно, вам придется играть с цифрами, чтобы получить то, что вы хотите, но дайте ListViewweight, скажем 0,8 и 0,2 для Button. Обязательно укажите height значение 0dp для обоих. Что-то вроде

<ListView 
    android:id="@+id/listCategory" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="0.8" 
    android:background="#FFFFFF" 
    android:gravity="top" /> 

<Button 
    android:id="@+id/btnManageCategory" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:onClick="onButtonClick" 
    android:text="Manage Category" 
    android:gravity="center" 
    android:layout_weight="0.2" 
    /> 
0
// try this 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listCategory" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="#FFFFFF" /> 

    <Button 
     android:id="@+id/btnManageCategory" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="onButtonClick" 
     android:text="Manage Category" 
     android:gravity="center"/> 

</LinearLayout> 
Смежные вопросы