【问题标题】:Android EditText within TableLayout runs offTableLayout中的Android EditText跑掉了
【发布时间】:2012-03-01 04:58:30
【问题描述】:

我在 tablelayout 中有一个简单的登录,但里面的内容向右伸展得太远了。在我看来,一切都以中心为中心。或者看起来 EditText 试图将自己置于主父级而不是它的父级表格布局中。知道为什么吗?

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bluebg"
android:id="@+id/loading_page_lin_layout"
>
 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/roundtable"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_margin="10dip"
        android:padding="10dip"
        android:stretchColumns="*">
        <TableRow>
            <EditText  
            android:id="@+id/txtUserName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#85AFBE"                              
            android:hint="Email"
            android:text=""
            android:gravity="left"

            />
         </TableRow>
        <TableRow>
            <EditText  
                android:id="@+id/txtPassword"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#85AFBE"                              
                android:text=""
                android:hint="Password"
                android:password="true"
                android:gravity="left"  
                android:layout_gravity="center"                     
                />
        </TableRow>
        <TableRow>
            <!--  <Button
            android:id="@+id/btnSignIn"
            android:text="Sign In" 
            android:layout_width="fill_parent"
            android:paddingTop="10dip"
            android:gravity="center"
            />-->
            <ImageButton 
             android:id="@+id/btnSignIn"
             android:src="@drawable/signbig"    
             android:scaleType="fitCenter"   
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"                
             android:adjustViewBounds="true"
             android:layout_marginLeft="3dip"
             android:background="@null"
             android:layout_marginRight="3dip"
             android:layout_gravity="center"
             />
        </TableRow>
        <TableRow>
            <Button
            android:id="@+id/btnSignUp"
            android:background="@null"
            android:text="Sign Up" 
            android:textStyle=""
            android:layout_width="wrap_content"
            android:paddingTop="10dip"
            android:textSize="20dip"
            android:gravity="center"
            android:onClick="SendToSignUp"
            />                          
        </TableRow> 
        <TableRow>
            <Button
               android:id="@+id/btnFillData"
               android:text="Fill Fake Data" 
               android:background="@null"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:paddingTop="10dip"
               android:gravity="center"
               android:onClick="FillFakeData"
               />
           </TableRow>
</TableLayout>
</LinearLayout>

【问题讨论】:

  • 您能否获得它的外观截图并将其放到网上某处,然后编辑您的问题并将链接粘贴到那里?能够实际看到它将使我们更容易帮助您解决问题。
  • 或者您可以在此处添加屏幕截图

标签: android android-edittext tablelayout


【解决方案1】:

我在两列表上遇到了同样的问题。 我在第二列中的文字被屏幕截断了。 通过在我的TableLayout 中使用android:shrinkColumns="1" 来修复它。

这是我的代码,text3 太大,在我在 TableLayout 中添加 shrinkColumns 属性之前被截断。

<TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="1" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            >

            <TextView
                android:id="@+id/text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp" />

            <TextView
                android:id="@+id/text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1" />
        </TableRow>
    </TableLayout>

【讨论】:

  • 这对我也有帮助!在旁注中 - 这可以在 Java 中使用 mTableLayout.setShrinkAllColumns(true); 完成
  • 请注意shrinkColumns 的值是您要缩小的列。不要读成1 == true
【解决方案2】:

您的表格布局的宽度设置为“wrap_content”,它的子级设置为“fill_parent”,没有一个人确切知道任何事情:) 将表格布局的宽度设置为“fill_parent”,所有内容都应按您的意思布置它到。

UPD 我只在您的表格中看到一列。这意味着您可以放心地将其替换为垂直 LinearLayout。

【讨论】:

  • 我试过了,又试了一次,没有什么不同。桌子内的所有东西都在右侧被切断。
  • 嗯。这很奇怪。但不管怎样,把它放在“fill_parent”,这是正确的方法,我会想更多。
  • 另外,更简单的解决方案是使用带有orientation="vertical" 的简单LinearLayout。您的布局似乎不够复杂,不需要 TableLayout,它可以使用 Linear。
  • 它必须有表,看屏幕截图。桌子是设计的一部分,边缘是圆形的。
  • 另外,尝试将 layout_gravity="center" 设置为您的第一个 EditText。这是我看到的它与似乎布局良好的密码字段之间的唯一区别。
【解决方案3】:

我遇到了同样的问题,网上的教程都没有帮助。最后,我发现设置表格视图的“收缩列”属性可以解决问题。

【讨论】:

    【解决方案4】:

    为运行EditText的列设置shrinkColumn和stretchColumn。这为您提供了与父级匹配的宽度并且不会流失。

    【讨论】:

      【解决方案5】:

      设置 EditTextView 的 layout_width="0dp" 和 layout_weight="1" 解决了我的问题。

      【讨论】:

        猜你喜欢
        • 2010-10-18
        • 2016-06-12
        • 2012-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-16
        • 1970-01-01
        相关资源
        最近更新 更多