简体   繁体   中英

Android different visualization on 2.x and 4.x

I'm having some trouble about visualization of items. On android 2.x xml fill the screen but in 4.x they cover about 50% of the screen and the other 50% it's all black. I think using fill_parent and wrap_content help me! How i can standardize it ? Here's the source

     <?xml version="1.0" encoding="utf-8"?>

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:background="#0058A8" >

       <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="#0058A8" >



       <EditText
           android:id="@+id/smsnumber"
           android:layout_width="154dp"
           android:layout_height="wrap_content"
           android:layout_alignParentLeft="true"
           android:layout_alignParentTop="true"
           android:layout_marginLeft="14dp"
           android:layout_toLeftOf="@+id/btnRubrica"
           android:ems="10"
           android:inputType="phone" >

       </EditText>

       <Button
           android:id="@+id/btnRubrica"
           android:layout_width="119dp"
           android:layout_height="wrap_content"
           android:layout_alignParentRight="true"
           android:layout_alignParentTop="true"
           android:text="@string/phone_book" />

</RelativeLayout>

       <EditText
           android:id="@+id/smstext"
           android:layout_width="fill_parent"
           android:layout_height="64dp"
           android:inputType="textMultiLine" />

<DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="fill_parent"
        android:layout_height="138dp"
        />

   <TimePicker
       android:id="@+id/timePicker1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
      />

   <Button
       android:id="@+id/start"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="@string/start" />

</LinearLayout>

The root of your layout has to be something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#0058A8"
    android:orientation="vertical" >

    <!-- The rest of your layout -->

</LinearLayout>

Notice the android:layout_width="fill_parent" and android:layout_height="fill_parent" properties.

There is no difference in rendering the layout between 2.x and 4.x. The only difference you saw was that the device with 2.x had smaller resolution than the 4.x one, there fore on the smaller screen the layout was filling up all the space .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM