TextView在屏幕上显示非常小

时间:2014-02-21 08:10:46

标签: android xml textview android-tablelayout

在我的应用程序中,我有以下布局,无论我给出什么值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父版本是无用的”。请指导我。

提前致谢。

5 个答案:

答案 0 :(得分:4)

尝试这一个而不是表使用线性布局和设置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>

答案 1 :(得分:2)

尝试这个....,你可以添加你想要给予的android:textSize =“some value”

    <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" />

答案 2 :(得分: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>

答案 3 :(得分:0)

使用以下方式给出文本大小:

android:textSize="some value"

答案 4 :(得分:0)

尝试根据您的要求给出大小,表格行的宽度和textview设置为match_parent,因此它(textview)不能改变它的大小。

android:layout_width="50dp"