簡體   English   中英

表格布局android中的TextView寬度

[英]TextView width in Table layout android

在我的應用程序屏幕中,我正在使用表格布局。在表格行中我有兩個文本視圖。第二個文本視圖的寬度總是超出屏幕寬度。我嘗試了 wrap_content,match_parent 但沒有得到如何解決這個問題。如何設置寬度設備屏幕布局寬度?

屏幕布局

xml代碼-

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@color/even" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical" >

        <TableLayout
            android:id="@+id/tableLayoutDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TableRow
                android:id="@+id/namerow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                >

                <TextView
                    android:id="@+id/nameText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="left"
                    android:text="Name" />

                <TextView
                    android:id="@+id/dname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="left"
                     android:background="@android:color/black"
                    android:text="Name :"
                    android:textColor="#808080" />
            </TableRow>
 </TableLayout>
</LinearLayout>
</ScrollView>

即使在為 TextView 提供 100dp 寬度后,它也會離開屏幕

這可能是 Android 圖形布局問題。 我在 Android View Design 中檢查了你的代碼。 TextView 字母不會超出布局。 如果您有疑問 將背景設置為文本視圖,看看發生了什么?

使用此代碼:完美運行(用此替換您的代碼並根據您的選擇進行修改)

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/include1"
        android:layout_marginTop="20dp"
        android:gravity="top"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="30dp"
            android:orientation="horizontal"
            android:weightSum="100" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="Name"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvfullname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text="sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_marginBottom="6dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="6dp"
            android:background="#e1e2dd" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="Birthday"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvbirth"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text=""
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_marginBottom="6dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="6dp"
            android:background="#e1e2dd" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="Gender"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvgender"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text=""
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_marginBottom="6dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="6dp"
            android:background="#e1e2dd" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="Mobile Number"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvmobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text=""
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_marginBottom="6dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="6dp"
            android:background="#e1e2dd" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="Email Id"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvemail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text="sjdhgvfkasvsjdgfjsgdfjhgskdjfgakjsgdflaghdfljashdgfljadgsfjahg"
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_marginBottom="6dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="6dp"
            android:background="#e1e2dd" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="Location"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvlocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text=""
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_marginBottom="6dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="6dp"
            android:background="#e1e2dd" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="100" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="35dp"
                android:layout_weight="50"
                android:gravity="left"
                android:text="City"
                android:textColor="#454545"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tvcity"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="left"
                android:text=""
                android:textColor="#454545"
                android:textSize="12sp" />
        </LinearLayout>
    </LinearLayout>
  </LinearLayout>

</ScrollView>

看這張圖片:

在此處輸入圖片說明

此致

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM