Android .xml设计
对于大多数.xml文件,我的设计中存在一些缺陷,其中一些屏幕上的尺寸通常较大,而较低的屏幕上的尺寸通常较大。我使用px(像素)。Android .xml设计
我知道这对我来说可能是一个糟糕的选择,因为新手机会以更高的像素比例结束。例如三星Galaxy Nexus将所有文本制作成小文本。
什么会是一个更合适的类型用于未来的电话来?
附加:
我已经使用了很长一段时间的线性布局,但现在,我需要一个滚动的长菜单我设计嵌套在滚动型,其滚动型嵌套的线性布局的RelativeLayout的。嵌套tableLayout以更好地控制视图会更好吗?
不想泛滥的问题屏幕因为它看起来丑陋。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tab_tv_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/auto_Action"
android:background="#666666"
android:text="@string/options_dialog_menu_Action"
android:textSize="27px"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/FirstOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/manual_Action"
android:layout_below="@+id/tab_tv_one"
android:text="@string/options_dialog_menu_Auto_Action"
android:textSize="27px" />
<RadioButton
android:id="@+id/SecondOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/tab_tv_two"
android:layout_below="@+id/auto_Action"
android:text="@string/options_dialog_menu_Manual_Action"
android:textSize="27px"
android:onClick="onClick"
android:clickable="true"
/>
<RadioButton
android:id="@+id/ThirdOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/tab_tv_two"
android:layout_below="@+id/manual_Action"
android:textSize="27px"
android:onClick="onClick"
android:clickable="true"
/>
</RadioGroup>
<TextView
android:id="@+id/tab_tv_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/text_size"
android:layout_below="@+id/manual_Action"
android:background="#666666"
android:text="@string/options_dialog_menu_Layout_Options"
android:textSize="27px"
/>
<TextView
android:id="@+id/text_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/background_clr"
android:layout_below="@+id/tab_tv_two"
android:text="@string/options_dialog_menu_Text_Size"
android:textSize="27px"
android:onClick="onClick"
android:clickable="true"
/>
<TextView
android:id="@+id/Options_clr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/brightness_ctrl"
android:layout_below="@+id/text_size"
android:text="@string/options_dialog_menu_Color_Options"
android:textSize="27px"
android:onClick="onClick"
android:clickable="true"
/>
<TextView
android:id="@+id/brightness_ctrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/background_clr"
android:text="@string/options_dialog_menu_Brightness_color"
android:textSize="27px"
android:onClick="onClick"
android:clickable="true"
/>
<TextView
android:id="@+id/backToBasics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/brightness_ctrl"
android:text="@string/options_dialog_menu_Back_To_Basics"
android:textSize="27px"
android:onClick="onClick"
android:clickable="true"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
不要使用像素,请使用dp(又名dip又称密度独立像素)。否则,如你所述,尺寸将取决于密度,这是不好的。
它不仅仅是星系之间的联系,ldpi电话看起来不同于mdpi,它看起来不同于hdpi等。很少有任何理由使用px尺寸,特别是关于视图尺寸。
关于你的额外问题,它完全取决于你想要你的布局看起来像什么。没有看到代码和/或至少知道你想要发生什么(相比你现在看到的),没有人真的能够回答这个问题。
我将添加代码。不想太多地淹没问题屏幕。 – sdfwer 2012-03-28 20:30:14
因此,除了将像素更改为dp(这将是一种痛苦,但完全值得),您不会做任何不合理的事情。除非让布局看起来像你想要的那样,否则就按原样放置。如果你发现你需要在桌面布局中使用功能,没有任何理由不使用它,我可以看到,并且当你真正需要它时,你可以随时切换。 – 2012-03-28 20:56:54
我认为你需要使用dp而不是像素。 – kosa 2012-03-28 20:26:43