2014-03-06 23 views
2

我一直遵守以下的链接,这样我的应用程序可以支持不同的屏幕尺寸:支持android系统多屏在单个布局

Supporting multiple screens in android

该解决方案完美的作品。但我担心的是,当我有一个具有8-9个屏幕的android应用程序时,这意味着我将拥有8-9个不同的.xml布局文件。现在为了支持文件夹分叉的所有屏幕,这意味着我已经管理了几乎50多个xml文件的布局和UI的简单更改,我必须去所有文件夹并在xml文件中实现该更改。那么能不能有一个更好的方法,我的意思是这样一种布局,可以调整控件本身或类似的东西?

回答

0

看看这个问题:LINK

然后,您可以制作包含常用的东西一个XML文件中的所有XML布局,然后为每个布局只包括或合并需要的通用XML的一部分,这样你只需编辑一次共同的XML文件,其他所有布局将包含新的更改。

3

我认为这不是太复杂。在布局文件夹中创建所有布局。使用styles.xml, dimens.xml and strings.xml保存字体大小和字符串。当您的布局完成后,即无需进行任何更改,则从布局文件夹复制所有这些布局,并粘贴到layout-small, layout-large, layout-xlarge。因此,当您需要更改字符串,样式和字体大小时,只需在值文件夹中进行更改。

对于示例 -

代替android:text="Hello"使用android:text="string/hello"和保存的strings.xml打招呼的价值。对于文本大小android:textSize="@dimen/btxt"也是如此。

这是最好的选择之一。

+0

基本上我想要的是,我不想有一个屏幕的多个布局文件。我想要写一些类似于我的layout.xml文件的文件,并且在该文件中,我使用了这样一种布局,可根据屏幕大小调整我的UI组件。就像我们在java swing应用程序中有Bag布局一样。 –

+0

我知道你要求你必须根据屏幕尺寸进行计算。然后根据此更改您的布局组件。但我不知道通过这种方式,你在每个屏幕上都有很好的布局。 –

+0

在此链接中检查一些基于计算的答案。希望它可以帮助你。 http://stackoverflow.com/questions/21274692/font-size-of-text –

1

我创建了一个相对大小单位。 可以使用此大小单位为所有屏幕构建一个布局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> 

,这里是结果:

enter image description here

注意的UI元素与屏幕尺寸按比例。