开发者

Android Density Problem

开发者 https://www.devze.com 2023-03-18 15:00 出处:网络
Now please consider my below code of android layout <?xml version=\"1.0\" encoding=\"utf-8\"?> <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"

Now please consider my below code of android layout

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

        <RelativeLayout 
                        android:id="@+id/RelativeLayout01" 
                        android:layout_width="wrap_content" 
                        android:layout_height="wrap_content">   
            <ImageView
                        android:layout_width="fill_parent" 
                        android:layout_height="fill_parent" 
                        android:background="@drawable/default1"
                        android:id="@+id/default1"
                        android:layout_gravity="center"
                        android:scaleType="fitXY">
            </ImageView>

            <ImageView
                        android:layout_marginTop="19dp"
                        android:layout_width="180dp" 
                        android:layout_height="45dp" 
                        android:src="@drawable/fc_postyour_best_score_bg"
                        android:id="@+id/postscore"
                        android:layout_alignParentRight="true"
                        android:scaleType="fitXY">
            </ImageView>   

            <ImageButton
                        android:layout_marginTop="22dp"
                        android:layout_width="35dp" 
                        android:layout_height="35dp" 
                        android:background="@drawable/fctwitterup"
                        android:layout_marginLeft="7dp"
                        android:id="@+id/twitter"
                        android:layout_alignRight="@id/postscore"
                        android:scaleType="fitXY">
            </ImageButton>

            <ImageButton
                        android:layout_marginTop="22dp"
                        android:layout_width="35dp" 
                        android:layout_height="35dp" 
                        android:background="@drawable/fcfacebookdown"
                        android:id="@+id/fb"
                        android:layout_toLeftOf="@id/twitter">
            </ImageButton>

            <ImageButton
                        android:layout_width="160dp" 
                        android:layout_height="40dp" 
                        android:background="@drawable/fsremove_ads_down"
                        android:id="@+id/fsremove_ads_down"                     
                        android:layout_below="@id/postscore"
                        android:layout_alignParentRight="true"
                        android:layout_marginBottom="3dp">
            </ImageButton>

            <ToggleButton 
                         android:id="@+id/fsvibrate_on"
                         android:layout_width="135dip"
                         android:layout_height="35dip"
          开发者_Python百科               android:textOff=""
                         android:textOn=""
                         android:layout_below="@+id/fsremove_ads_down"
                         android:layout_alignParentRight="true"
                         android:background="@drawable/fsvibrate_on">
            </ToggleButton>

            <ImageButton
                        android:layout_width="210dp" 
                        android:layout_height="60dp" 
                        android:background="@drawable/fcplaydown"
                        android:id="@+id/fcplaydown"
                        android:layout_centerInParent="true">
            </ImageButton>

            <ToggleButton 
                        android:id="@+id/fcsoundondown"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:textOff=""
                        android:textOn=""
                        android:layout_below="@+id/fcplaydown"
                        android:background="@drawable/fcsoundondown">
            </ToggleButton>


        </RelativeLayout>

</LinearLayout>

I have problems:

. I have use dp for setting height,margin,width etc. but it varies as devices get change what should I take care for unique layout setting


You should look over the net and read more about proportional UI in android. Different devices - different resolutions (not mandatory, but in most cases), so how do you want to have same UI on different devices, when you're using static measures. And your RelativeLayout, it is such a mess! Here is an other post, which explains the basic about proportions. Proportional width of elements in LinearLayout

It applies for RelativeLayout also!


  1. dont use + on id property when setting layout_below

    android:layout_below="@+id/fcplaydown" --> android:layout_below="@id/fcplaydown"

  2. Using dp or dip is best option. Images sometimes represent problems if no height and width in dp is defined


Use Linear Layout for those images you want to show one below the other. Hope this works.

0

精彩评论

暂无评论...
验证码 换一张
取 消