根据Android中的屏幕大小为元素指定宽度

时间:2016-08-31 12:51:49

标签: android

我在activity.xml中的RelativeLayout中有以下视图:

> <TextView
>         android:id="@+id/clr_title"
>         android:layout_width="@dimen/Que_text"
>         android:layout_height="wrap_content"
>         android:layout_marginTop="33dp"
>         android:text="TextView" />
> 
>     <Spinner
>       android:id="@+id/clr_spinner"
>       android:layout_marginLeft="20dp"
>       android:layout_width="@dimen/Que_spinner"
>       android:layout_height="wrap_content"
>       android:spinnerMode="dropdown"
>       android:layout_marginTop="15dp"
>       android:layout_toEndOf="@+id/clr_title" />

这意味着我的观点与另一个观点相邻。我已经分配了动态宽度(使用dimens.xml)。

我正在测试Galaxy Tab 3(8&#34; 1280x800)和Nexus 5(5&#34; 1920x1080)。 我希望TextView的宽度在Nexus上为200dp,在Galaxy选项卡上为500dp,以便两个设备都可以看到。

我应该创建哪些文件夹来根据屏幕大小指定宽度? 我可以创造一个&#34;价值观&#34;基于英寸的文件夹?

1 个答案:

答案 0 :(得分:1)

必须遵循值文件夹

中的尺寸

values (normal phones) eg:1dp values-large(7 inch Tablets) eg:1.5dp values-xlarge(10 inch Tablets) eg:2dp

valuesvalues-largevalues-xlarge

的每个维度都会有所不同