проблема с пользовательским интерфейсом кнопок изображений в приложении для Android - PullRequest
1 голос
/ 05 июля 2011

в моем приложении я помещаю 4 кнопки изображения в нижней части страницы. Но согласно моему макету изображение выглядит по-разному в каждом устройстве. Я хочу, чтобы изображение было одинаковым на всех устройствах.

Ниже приведено расположение кнопок моего изображения

 <LinearLayout android:layout_height="wrap_content" android:id="@+id/tabLayout" android:layout_width="match_parent" 
           android:background="@drawable/tab_bar" android:orientation="horizontal" android:layout_weight="0.1">
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_height="match_parent" android:layout_width="match_parent">
        <ImageButton android:layout_marginLeft="35dip" android:layout_height="wrap_content" android:id="@+id/homeBtn" android:background="@drawable/home"   android:layout_width="wrap_content" android:layout_gravity="center"></ImageButton>
        <ImageButton android:layout_marginLeft="35dip" android:layout_toRightOf="@+id/homeBtn" android:layout_height="wrap_content" android:id="@+id/addBtn"  android:background="@drawable/add"    android:layout_width="wrap_content" android:layout_gravity="center"></ImageButton>
        <ImageButton android:layout_marginLeft="35dip" android:layout_toRightOf="@+id/addBtn" android:layout_height="wrap_content" android:id="@+id/srchBtn" android:background="@drawable/search" android:layout_width="wrap_content" android:layout_gravity="center"></ImageButton>
        <ImageButton android:layout_marginLeft="35dip" android:layout_toRightOf="@+id/srchBtn" android:layout_height="wrap_content" android:id="@+id/helpBtn" android:background="@drawable/help"   android:layout_width="wrap_content" android:layout_gravity="center"></ImageButton>          
    </RelativeLayout>                               

Ниже приведены изображения моего макета. Я хочу, чтобы мой макет был таким, как на изображении image1, а изображение2 в настоящее время является изображением, которое я получаю.

enter image description here

Как получить как на картинке 1 во всех андроид устройствах. Пожалуйста, помогите мне друзья

Ответы [ 2 ]

1 голос
/ 05 июля 2011

Поскольку другие уже упоминали, что лучше всего использовать линейный макет, но вам также необходимо обеспечить заполнение линейного макета, я полагаю, 5dp должно выглядеть хорошо.

Вот как это может выглядеть:

enter image description here

А вот и код того же

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:orientation="horizontal"
    android:padding="5dp" android:background="#a0a0a0"
    android:layout_height="wrap_content">
    <Button android:text="Button" android:id="@+id/button2"
        android:layout_width="0dp" android:layout_weight="1"
        android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button1"
        android:layout_width="0dp" android:layout_weight="1"
        android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button3"
        android:layout_width="0dp" android:layout_weight="1"
        android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button4"
        android:layout_width="0dp" android:layout_weight="1"
        android:layout_height="wrap_content"></Button>

</LinearLayout>
0 голосов
/ 05 июля 2011

Я бы порекомендовал вам использовать LinearLayout.Гораздо проще выровнять кнопки по горизонтали, используя его.Просто установите их android:layout_width свойство на fill_parent и android:layout_weight на 1.Надеюсь, это поможет.

...