2014-11-06 76 views
-1

我正在开发一个21.5英寸android设备的应用程序。我已经尝试了下面的代码并在10英寸的仿真器中测试。它看起来不错。但我想知道是否使用相对布局或线性布局与重量是好的。因为我不想在21.5英寸屏幕上出现布局下方的空白区域。请建议。21.5英寸屏android设备的布局设计

我的布局代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:adjustViewBounds="true" 
    android:contentDescription="@string/app_name" 
    android:src="@drawable/image1" /> 

<com.acuvue.kiosk.view.CustomTextView 
    android:id="@+id/customTextView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView1" 
    android:layout_centerInParent="true" 
    android:layout_marginTop="100dp" 
    android:gravity="center" 
    android:text="@string/please_choose" 
    android:textSize="50sp" 
    android:textStyle="bold" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/customTextView1" 
    android:layout_marginTop="100dp" 
    android:baselineAligned="false" 
    android:orientation="horizontal" 
    android:weightSum="2" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/hello_world" 
      android:textColor="#ffffff" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" > 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="@string/hello_world" 
      android:textColor="#ffffff" /> 
    </LinearLayout> 
</LinearLayout> 

+0

哪个设备提供21.5英寸的屏幕? – 2014-11-06 05:38:18

+1

@HareshChhelana hp slate 21 android平板电脑。 – 2014-11-06 05:39:25

回答

0

试试这个办法,希望这将帮助你解决你的问题。

这里使用LinearLayout的重量而不是Relativelayout。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitXY" 
      android:src="@drawable/image1" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:gravity="center"> 

      <com.acuvue.kiosk.view.CustomTextView 
       android:id="@+id/customTextView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="@string/please_choose" 
       android:textSize="50sp" 
       android:textStyle="bold" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:gravity="center"> 
      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center"> 
       <Button 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/hello_world" 
        android:textColor="#ffffff" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center"> 
       <Button 
        android:id="@+id/button2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/hello_world" 
        android:textColor="#ffffff" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
+0

我会试试这个。你知道关于如何在21.5屏幕 – 2014-11-06 05:58:23

+0

@ BalajiDhanasekar测试它的任何建议,没有人知道这种类型的分辨率甚至不适用于模拟器。 – 2014-11-06 06:00:05

+0

好的。我认为它会匹配任何屏幕尺寸,如果我们使用重量线性布局。不是吗? – 2014-11-06 06:15:56