Пользовательский интерфейс Проблема Android - PullRequest
3 голосов
/ 21 января 2012

Я делаю Android Пользовательский интерфейс (с использованием Relative Layout), в котором мне нужно установить один баннер, размер которого 306 x 51. Я установил его как центр экрана. и он хорошо отображается на экране мобильного телефона Android, но когда я запускаю в планшете, дисплей выглядит так:

enter image description here

как показано на рисунке, пробел остается слева и справа. так что я для этого делаю?

Код:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:background="@drawable/page1_11"
    android:layout_height="fill_parent">


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_01" android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView android:layout_height="wrap_content"
            android:layout_width="match_parent" android:src="@drawable/page1_1"
            android:id="@+id/imageView1" android:layout_alignParentLeft="true" />

        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text="Shanesh COLORS App"
            android:textSize="13dp" android:textStyle="bold" android:textColor="#49515F"
            android:layout_centerInParent="true" />
    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_below="@+id/login_rellay_01" android:id="@+id/login_rellay_02"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ImageView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:src="@drawable/page1_4"
            android:id="@+id/imageView1" android:layout_centerHorizontal="true" />

        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text="SIGN IN"
            android:textSize="13dp" android:textStyle="bold" android:textColor="#FFFFFF"
            android:layout_centerInParent="true" />
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:background="@drawable/page1_2"
            android:layout_centerVertical="true" android:layout_marginLeft="10dp" />
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:background="@drawable/page1_3"
            android:layout_centerVertical="true" android:layout_marginRight="10dp"
            android:layout_alignParentRight="true" />


    </RelativeLayout>



    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_03" android:layout_below="@+id/login_rellay_02"
        android:layout_width="match_parent" android:layout_height="wrap_content">


        <ImageView android:layout_height="wrap_content"
            android:layout_width="match_parent" android:src="@drawable/page1_5"
            android:id="@+id/imgv_page1_5" android:layout_alignParentLeft="true" />
        <!-- <ImageView android:layout_height="wrap_content" android:layout_below="@+id/imgv_page1_5" 
            android:layout_marginTop="1dp" android:layout_width="match_parent" android:src="@drawable/page1_6" 
            android:id="@+id/imgv_page1_6" android:layout_alignParentLeft="true" /> -->
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_rellay_03" android:layout_centerInParent="true"
            android:layout_below="@+id/login_rellay_02" android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content" android:text="SIGN IN "
                android:textSize="13dp" android:id="@+id/login_txvx_dwbnr_1"
                android:textStyle="bold" android:textColor="#000000"
                android:layout_marginLeft="10dp" android:layout_centerVertical="true" />
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content" android:text="with your "
                android:id="@+id/login_txvx_dwbnr_2" android:layout_toRightOf="@+id/login_txvx_dwbnr_1"
                android:textSize="13dp" android:layout_centerVertical="true"
                android:textColor="#000000" />
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content" android:text="Shanesh Colors"
                android:id="@+id/login_txvx_dwbnr_3" android:layout_toRightOf="@+id/login_txvx_dwbnr_2"
                android:textSize="13dp" android:textStyle="bold"
                android:layout_centerVertical="true" android:textColor="#000000" />
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content" android:text=" App Account "
                android:id="@+id/login_txvx_dwbnr_4" android:layout_toRightOf="@+id/login_txvx_dwbnr_3"
                android:textSize="13dp" android:layout_centerVertical="true"
                android:textColor="#000000" />
        </RelativeLayout>
    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_04" android:layout_marginTop="1dp"
        android:gravity="center" android:layout_below="@+id/login_rellay_03"
        android:layout_width="match_parent" android:layout_height="wrap_content">

        <ImageView android:layout_height="180dp"
            android:layout_width="306dp" android:background="#FFFFFF" android:id="@+id/imgv_page1_6"
            android:layout_centerInParent="true" />



        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_rellay_04" android:layout_width="match_parent"
            android:layout_height="wrap_content" android:gravity="center">
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content" android:text="User Name:"
                android:id="@+id/login_txvx_dwbnr_5" android:layout_toRightOf="@+id/login_txvx_dwbnr_1"
                android:textSize="11dp" android:layout_centerVertical="true"
                android:textColor="#49515F" />

            <EditText android:layout_height="40dp" android:layout_width="220dp"
                android:layout_marginTop="10dp" android:layout_toRightOf="@+id/login_txvx_dwbnr_5" />



        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_rellay_05" android:layout_width="match_parent"
            android:layout_height="wrap_content" android:gravity="center"
            android:layout_below="@+id/login_rellay_04">
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:text=" Password:"
                android:id="@+id/login_txvx_dwbnr_5" 
                android:layout_toRightOf="@+id/login_txvx_dwbnr_1"
                android:textSize="11dp" 
                android:layout_centerVertical="true"
                android:textColor="#49515F" />

            <EditText android:layout_height="40dp" android:layout_width="220dp"
                android:layout_alignParentTop="true" android:layout_marginTop="10dp"
                android:layout_toRightOf="@+id/login_txvx_dwbnr_5" />



        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_rellay_06" 
            android:layout_marginTop="3dp"
            android:layout_height="wrap_content"
            android:gravity="center" 
            android:layout_below="@+id/login_rellay_05" 
            android:layout_width="match_parent">

            <TextView android:layout_height="wrap_content"
                      android:textColor="#000000"
                      android:text="No Account?"

                      android:textStyle="bold"
                      android:textSize="11dp" 
                      android:id="@+id/login_txvx_dwbnr_9" 

                      android:layout_width="wrap_content"/>

        <TextView android:text="Sign Up" 
          android:layout_height="wrap_content"
          android:layout_width="wrap_content" 
          android:id="@+id/login_txvx_signup_account" 
          android:textColor="#8891A2" 
          android:textStyle="bold" 
          android:layout_toRightOf="@+id/login_txvx_dwbnr_9"
          android:textSize="11dp" 
         /></RelativeLayout>
         <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_rellay_07" 

            android:layout_height="wrap_content"
            android:gravity="center_horizontal" 
            android:layout_below="@+id/login_rellay_06" 
            android:layout_width="match_parent">

         <CheckBox android:layout_height="wrap_content"
                android:id="@+id/checkBox1"
                android:layout_below="@+id/login_txvx_signup_account"
                android:layout_width="wrap_content" 
                android:textColor="#49515F" 
                android:textSize="11dp"
                android:layout_marginLeft="10dp"
                android:text=" Remember User Name and Password?" 
          />

          </RelativeLayout>





    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_rellay_08" 

            android:layout_height="wrap_content"
            android:gravity="center_horizontal" 
            android:layout_marginTop="60dp"
            android:layout_below="@+id/login_rellay_04" 
            android:layout_width="match_parent">

          <ImageView android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/page1_8"
                     />
          </RelativeLayout>
</RelativeLayout>

Ответы [ 3 ]

0 голосов
/ 21 января 2012

Это связано с тем, что ширина планшета превышает 306. Поэтому баннер отображается в центре экрана, но с шириной, необходимой для изображения баннера. попробуйте следующий

вы используете

android: layout_width = "wrap_content"

для ImageView, в котором вы устанавливаете свой баннер

пожалуйста, попробуйте использовать

андроида: layout_width = "match_parent"

вместо этого. Другой способ - поместить изображение баннера большого размера в папку / drawable-xlarge в соответствии с размером экрана вашего планшета

0 голосов
/ 21 января 2012

@ zam664 правильно ... вы никогда не должны использовать фиксированную ширину для макетов ... попробуйте управлять ими с помощью отступов, полей и т. Д.

Используйте LinearLayout для управления горизонтальными дочерними элементами с нефиксированной шириной.

в любом случае ... я немного изменил ваш xml ... я не смог проверить его полностью, так как у меня не было изображений / ресурсов, которые вы использовали в нем ... но попробуйте.

Заменить весь XML следующим. ...

Примечание: a только что немного изменил его, чтобы дать вам представление ... вам следует изменить его, если это работает

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 
android:background="@drawable/page1_11"
android:layout_height="fill_parent">


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/login_rellay_01" android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView android:layout_height="wrap_content"
        android:layout_width="match_parent" android:src="@drawable/page1_1"
        android:id="@+id/imageView1" android:layout_alignParentLeft="true" />

    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Shanesh COLORS App"
        android:textSize="13dp" android:textStyle="bold" android:textColor="#49515F"
        android:layout_centerInParent="true" />
</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_below="@+id/login_rellay_01" android:id="@+id/login_rellay_02"
    android:layout_width="fill_parent" android:layout_height="wrap_content">
    <ImageView android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:src="@drawable/page1_4"
        android:id="@+id/imageView1" android:layout_centerHorizontal="true" />

    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="SIGN IN"
        android:textSize="13dp" android:textStyle="bold" android:textColor="#FFFFFF"
        android:layout_centerInParent="true" />
    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/page1_2"
        android:layout_centerVertical="true" android:layout_marginLeft="10dp" />
    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/page1_3"
        android:layout_centerVertical="true" android:layout_marginRight="10dp"
        android:layout_alignParentRight="true" />


</RelativeLayout>



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/login_rellay_03" android:layout_below="@+id/login_rellay_02"
    android:layout_width="match_parent" android:layout_height="wrap_content">


    <ImageView android:layout_height="wrap_content"
        android:layout_width="match_parent" android:src="@drawable/page1_5"
        android:id="@+id/imgv_page1_5" android:layout_alignParentLeft="true" />
    <!-- <ImageView android:layout_height="wrap_content" android:layout_below="@+id/imgv_page1_5" 
        android:layout_marginTop="1dp" android:layout_width="match_parent" android:src="@drawable/page1_6" 
        android:id="@+id/imgv_page1_6" android:layout_alignParentLeft="true" /> -->
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_03" android:layout_centerInParent="true"
        android:layout_below="@+id/login_rellay_02" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text="SIGN IN "
            android:textSize="13dp" android:id="@+id/login_txvx_dwbnr_1"
            android:textStyle="bold" android:textColor="#000000"
            android:layout_marginLeft="10dp" android:layout_centerVertical="true" />
        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text="with your "
            android:id="@+id/login_txvx_dwbnr_2" android:layout_toRightOf="@+id/login_txvx_dwbnr_1"
            android:textSize="13dp" android:layout_centerVertical="true"
            android:textColor="#000000" />
        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text="Shanesh Colors"
            android:id="@+id/login_txvx_dwbnr_3" android:layout_toRightOf="@+id/login_txvx_dwbnr_2"
            android:textSize="13dp" android:textStyle="bold"
            android:layout_centerVertical="true" android:textColor="#000000" />
        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text=" App Account "
            android:id="@+id/login_txvx_dwbnr_4" android:layout_toRightOf="@+id/login_txvx_dwbnr_3"
            android:textSize="13dp" android:layout_centerVertical="true"
            android:textColor="#000000" />
    </RelativeLayout>
</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/login_rellay_04" android:layout_marginTop="1dp"
    android:gravity="center" android:layout_below="@+id/login_rellay_03"
    android:layout_width="match_parent" android:layout_height="wrap_content">

    <ImageView android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:background="#FFFFFF" android:id="@+id/imgv_page1_6"
        android:layout_centerInParent="true" />



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_04" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="horizontal" 
        android:paddingLeft="10dp" android:paddingRight="10dp">
        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:text="User Name:"
            android:id="@+id/login_txvx_dwbnr_5" android:layout_toRightOf="@+id/login_txvx_dwbnr_1"
            android:textSize="11dp" android:layout_centerVertical="true"
            android:textColor="#49515F" />

        <EditText android:layout_height="40dp" android:layout_width="fill_parent" android:layout_weight="1"
            android:layout_marginTop="10dp" android:layout_marginLeft="10dp"/>



    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_05" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="horizontal"
        android:paddingLeft="10dp" android:paddingRight="10dp"
        android:layout_below="@+id/login_rellay_04">
        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content" 
            android:text=" Password:"
            android:id="@+id/login_txvx_dwbnr_5" 
            android:layout_toRightOf="@+id/login_txvx_dwbnr_1"
            android:textSize="11dp" 
            android:layout_centerVertical="true"
            android:textColor="#49515F" />

        <EditText android:layout_height="40dp" android:layout_width="fill_parent"  android:layout_weight="1"
            android:layout_alignParentTop="true" android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/login_txvx_dwbnr_5" />



    </LinearLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_06" 
        android:layout_marginTop="3dp"
        android:layout_height="wrap_content"
        android:gravity="center" 
        android:layout_below="@+id/login_rellay_05" 
        android:layout_width="match_parent">

        <TextView android:layout_height="wrap_content"
                  android:textColor="#000000"
                  android:text="No Account?"

                  android:textStyle="bold"
                  android:textSize="11dp" 
                  android:id="@+id/login_txvx_dwbnr_9" 

                  android:layout_width="wrap_content"/>

    <TextView android:text="Sign Up" 
      android:layout_height="wrap_content"
      android:layout_width="wrap_content" 
      android:id="@+id/login_txvx_signup_account" 
      android:textColor="#8891A2" 
      android:textStyle="bold" 
      android:layout_toRightOf="@+id/login_txvx_dwbnr_9"
      android:textSize="11dp" 
     /></RelativeLayout>
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_07" 

        android:layout_height="wrap_content"
        android:gravity="center_horizontal" 
        android:layout_below="@+id/login_rellay_06" 
        android:layout_width="match_parent">

     <CheckBox android:layout_height="wrap_content"
            android:id="@+id/checkBox1"
            android:layout_below="@+id/login_txvx_signup_account"
            android:layout_width="wrap_content" 
            android:textColor="#49515F" 
            android:textSize="11dp"
            android:layout_marginLeft="10dp"
            android:text=" Remember User Name and Password?" 
      />

      </RelativeLayout>





</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_rellay_08" 

        android:layout_height="wrap_content"
        android:gravity="center_horizontal" 
        android:layout_marginTop="60dp"
        android:layout_below="@+id/login_rellay_04" 
        android:layout_width="match_parent">

      <ImageView android:layout_height="wrap_content"
                 android:layout_width="wrap_content"
                 android:src="@drawable/page1_8"
                 />
      </RelativeLayout>

0 голосов
/ 21 января 2012

Вы не можете использовать фиксированные размеры, если ожидается, что ваши пропорции или размеры экрана будут отличаться. Вот почему Java сосредоточилась на том, чтобы менеджеры компоновки были более независимыми от платформы, чем предыдущие методы разработки Windows, которые требовали измерений. Принудительные размеры плохие.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...