2014-03-06 40 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元素與屏幕尺寸按比例。