2014-02-21 128 views
1

在我的应用程序中,我有以下布局,不管我给textview的值是什么,都不会改变它的宽度。有人可以帮助我纠正这种布局。TextView在屏幕上显示很小

下面是XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 
android:layout_marginTop="15dp" 
android:descendantFocusability="blocksDescendants" > 

<TableRow 
    android:layout_width="match_parent" 
    android:gravity="center_horizontal" > 

    <TextView 
     android:id="@+id/rec_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/fill_rece" 
     android:ems="10" 
     android:focusable="false" 
     android:padding="10dp" 
     android:textColor="#FFFFFF" /> 

    <ImageButton 
     android:id="@+id/btn_rec_delete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/content" 
     android:src="@drawable/ipad_postcare_landscape_from" /> 
</TableRow> 

</TableLayout> 

我还得到附近的TableRow警告说:“这种布局的TableRow或其TableLayout父母也没用”。请指导我。

在此先感谢。

+0

你尝试“FILL_PARENT”为TextView中的“layout_width”属性的文本视图和图像按钮空间等量的? – user1406716

+2

@ user1406716'fill_parent'已弃用,使用'match_parent'是正确的。 –

+3

remove'android:ems =“10”' –

回答

4

尝试使用表线性布局的这一个insted的用,并设置LAYOUT_WEIGHT属性。这地产股

<?xml version="1.0" encoding="utf-8"?> 


<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 

<TextView 
    android:id="@+id/rec_name" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="@drawable/fill_rece" 
    android:focusable="false" 
    android:padding="10dp" 
    android:textColor="#FFFFFF" /> 

<ImageButton 
    android:id="@+id/btn_rec_delete" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:contentDescription="@string/content" 
    android:src="@drawable/ipad_postcare_landscape_from" /> 
</LinearLayout> 
+0

试过了。宽度没有变化。 – user2688158

+0

@ user2688158现在试试这个我编辑我的帖子... – Aravin

+0

不再改变。 – user2688158

0

给使用TEXTSIZE:

android:textSize="some value" 
+0

已经尝试过。不改变 – user2688158

1

您可能需要使用

android:layout_weight 

我提的一个例子对你有所帮助,也请确保你的每一个元素都有身高和体重有了它,以正确显示所有内容

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:background="@drawable/layout_border" 
android:weightSum="1.0" 
android:id="@+id/r1c1r2"> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:textIsSelectable="true" 
      android:id="@+id/key"/> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:textIsSelectable="true" 
      android:id="@+id/key2" /> 
</LinearLayout> 
0

尝试根据您的要求给出尺寸您有wid表行和textview中的第一行设置为match_parent,因此它(textview)无法更改它的大小。

android:layout_width="50dp" 
+0

我试过所有可能的值..不改变宽度 – user2688158

+1

我认为问题是在你的行android:background =“@ drawable/fill_rece”。你必须在xml文件中定义宽度大小。试图删除可绘制的文件,并改变宽度..它的作品! – goonerDroid

+1

是的,这是可能的,我会尝试获得更好的drawable,看看它是否有任何区别。不管怎么说,多谢拉。 – user2688158

2

试试这个....,你可以添加机器人:TEXTSIZE =“一些价值”,你想给

<TextView 
     android:id="@+id/rec_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     android:padding="10dp" 
     android:text="hllo" 
     android:textSize="25dp" /> 
+0

感谢您的回复,但上述方法不起作用。 – user2688158