2015-02-07 34 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”。然而,分配权重始终是一个更好的解决方案..

相关问题