2015-02-07 63 views
1
<TextView 
      android:id="@+id/text" 
      android:layout_width="@dimen/width_chat" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/left" 
      android:fontFamily="calibri" 
      android:padding="8dp" 
      android:textColor="#636363" 
      android:background="@anim/mercy" 
      android:textSize="17dp" /> 

這是我的文本視圖。我有屏幕尺寸4和6英寸。我想設置寬度,以便根據它自動調整。我在valuesvalues-sw600dp中創建了2維文件。在這兩個文件夾中,我已分別設置尺寸寬度250dp和150,但無法根據不同的文件設置尺寸。請幫助我,並建議我在哪裏做錯了。如何在Android中爲不同的屏幕尺寸寬度設置文本視圖寬度?

+0

你確定你有正確寬度值dimens.xml文件?如果寬度未根據您在文件中設置的參數設置,那意味着您正在將文件設置爲錯誤文件。 – NightFury 2015-02-09 06:46:04

+0

看到我有2設備我們有文件夾值,值-sw600dp,值-sw720dp-land,值-v11,值-v14我必須爲此設置 – Edge 2015-02-09 06:52:38

回答

1

對每個孩子使用橫向LinearLayoutandroid:layout_weight屬性。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <View 
     android:id="@+id/left" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 
    </View> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
</LinearLayout> 

如果你想使用尺寸文件(例如,設置text_size),在相應的文件夾中dimens.xml輸入值。

res/values/dimens.xml 
res/values-small/dimens.xml 
res/values-normal/dimens.xml 
res/values-large/dimens.xml 
res/values-xlarge/dimens.xml 
+0

我們不能使用尺寸文件嗎? – Edge 2015-02-07 10:23:31

1

你可能只是還嘗試在「PX」來定義維度,而不是「DP」。然而,分配權重始終是一個更好的解決方案..

相關問題