我使用了以下链接,以便我的应用程序可以支持不同的屏幕大小:
Supporting multiple screens in android
这个解决方案效果很好。但我在这里担心的是,当我有一个8-9个屏幕的安卓应用程序时,这意味着我将有8-9个不同的.xml布局文件。现在为了支持文件夹分支的所有屏幕,这意味着我已经管理了几乎50多个用于布局和UI的简单更改的xml文件,我必须转到所有的文件夹并在xml文件中实现该更改。所以有没有更好的方法,我的意思是这样的布局,可以自己调整控件的大小或类似的东西?
发布于 2014-03-06 18:20:51
我认为这并不太复杂。在layout文件夹中创建所有布局。使用styles.xml, dimens.xml and strings.xml
保存字体大小和字符串。当你的布局定稿时,即不需要更改,然后从布局文件夹复制所有这些布局并粘贴到layout-small, layout-large, layout-xlarge
中。因此,当您需要更改字符串、样式和字体大小时,您只能在values文件夹中进行更改。
例如:
使用android:text="string/hello"
而不是android:text="Hello"
,并在strings.xml中保存hello的值。文本大小android:textSize="@dimen/btxt"
也是如此。
这是最好的选择之一。
发布于 2015-02-19 18:40:58
我创建了一个相对大小的单位。此大小单位可用于为所有屏幕构建一个布局xml文件。此大小单位可通过链接sdp sdk获得。以下是使用此sdk构建的布局XML的示例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/give_us_a_review_landmine_main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/_27sdp"
android:paddingLeft="@dimen/_43sdp"
android:paddingRight="@dimen/_43sdp"
android:paddingTop="@dimen/_50sdp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Intuit"
android:textColor="@android:color/black"
android:textSize="@dimen/_40sdp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_minus10sdp"
android:paddingBottom="@dimen/_15sdp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="♡"
android:textColor="#ED6C27"
android:textSize="@dimen/_70sdp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="U"
android:textColor="@android:color/black"
android:textSize="@dimen/_70sdp" />
</LinearLayout>
<TextView
android:id="@+id/give_us_a_review_landmine_text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="@dimen/_12sdp"
android:text="Rate us so we can grow and help more people get their finances in check"
android:textColor="@android:color/black"
android:textSize="@dimen/_16sdp" />
<TextView
android:id="@+id/give_us_a_review_landmine_text_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="★★★★★"
android:textColor="#747474"
android:textSize="@dimen/_22sdp"
android:textStyle="bold" />
<Button
android:id="@+id/give_us_a_review_landmine_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/_25sdp"
android:padding="@dimen/_8sdp"
android:text="Rate"
android:textSize="@dimen/_15sdp"
android:visibility="visible"
android:textColor="@android:color/white"
android:gravity="center"
android:minWidth="120dp"
android:includeFontPadding="false"
android:background="#0ac775"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
结果如下:
请注意,UI元素随屏幕大小而缩放。
发布于 2014-03-06 18:06:52
看一下这个问题:LINK
然后,您可以创建一个包含所有XML布局中的通用内容的单个XML文件,然后对于每个布局,只需包含或合并所需的通用XML部件,这样您只需编辑通用XML文件一次,然后所有其他布局都将包含新的更改。
https://stackoverflow.com/questions/22220962
复制相似问题