【问题标题】:Is there an Answer for EditText cutt off inside TableLayout?在 TableLayout 中是否有 EditText 的答案?
【发布时间】:2013-04-15 03:47:09
【问题描述】:

Android EditText within TableLayout runs off 注意我发布这个是因为接受的答案在 cmets 中并且涉及切换到 LinearLayout。被列为已回答,但我遇到了类似的问题,切断了右边,但没有跑掉。将 TableLayout 宽度设置为 fill_parent 并不能解决此问题。 EditText 的右侧在 table_layout 内看起来像截断。

更新:请注意 EditText 不会超出边缘。它有 10dip 的保证金,但被砍掉了。我的意思是右边缘在选择时没有突出显示颜色。右上角没有形状。

 <?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>
         <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:paddingRight="15dip"
        android:text="Name:" />
        <EditText  
        android:id="@+id/txtUserName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#85AFBE"                              
        android:hint="Email"
        android:text=""

        android:paddingRight="15dip"
        android:layout_marginRight="10dip"
        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>

【问题讨论】:

  • 您能否提供您的 XML 布局、任何适用的代码和屏幕截图?这里没有信息让我们能够做任何事情。
  • 我已经发布了。与上一个问题的唯一区别是我在 EditText 左侧有文本视图,否则完全相同的问题。
  • 请注意上一个问题的公认答案涉及取消 TableLayout 并将其替换为 LinearLayout 是一个好主意,但我想知道 TableLayout 是否可以处理 EditText。
  • 请证明投反对票的合理性?谁?
  • 嗯,看起来你的第一行有 2 列(2 个元素,TextView 和 EditText)你也可以发布截图吗?也许你的按钮太大了? signbig 是 .9.png 吗?

标签: android


【解决方案1】:

我遇到了类似的问题,发现解决方案只是从 EditText 字段中删除 android:layout_width 属性。请参阅以下精炼布局:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
    <TextView android:text="Username"
        style="@style/DkTextStyle" />
    <EditText android:id="@+id/userText"
        android:layout_width="wrap_content"
        android:inputType="text" />
</TableRow>
</TableLayout>

使用上述布局,如果您在 EditText 字段中输入大量文本,则会导致框超出屏幕右侧出现截断。如果您从 EditText 中完全删除 android:layout_width 属性,它的行为会正常 - 这意味着框将滚动文本并且右边缘仍然可见。

【讨论】:

    【解决方案2】:

    我会尝试使用TableLayout 中的最后三个参数。

    android:layout_margin="10dip"
    android:padding="10dip"
    android:stretchColumns="*"
    

    TableLayouts 有点挑剔,不像 HTML 表格。我怀疑它是在应用填充和边距之前测量孩子。尝试将它们设置为零或 100,看看会发生什么。

    另外,如果您将match_parent 设置为TableLayout width,那么您不需要拉伸列,因为您使用的是单个列。我会设置一个或另一个。

    希望有帮助

    【讨论】:

    • 还是不行。但这并不是说这个 EditText 超出了边缘。它的边缘是边缘,但右边缘看起来被切掉了。例如,即使左侧、顶部和底部边缘有,它也没有高亮颜色。它的右边缘也没有固化的角落等
    • 我已编辑顶部布局以显示 TableLayout 和 EditText 的当前设置。
    【解决方案3】:

    TableLayouts 由 TableRows 组成,但 tablerow 中的列与 tableLayout 中的每个其他 tablerow 具有相同的宽度。列是按顺序填充的,因此您放入 tablerow 的第一件事是在第一列中。如果您对表格布局中的视图宽度有疑问,请检查该列中其他行中其他视图的宽度。

    【讨论】:

      猜你喜欢
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多