2014-02-21 129 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