проблема с пользовательским интерфейсом кнопок изображений в приложении для Android

1

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

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

 <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, а image2 - это образ, который я получаю.

Изображение 174551

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

Теги:
user-interface
relativelayout

2 ответа

1
Лучший ответ

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

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

Изображение 174551

И вот код для того же

<?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

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

Ещё вопросы

Сообщество Overcoder
Наверх
Меню