Android TableLayout 内的 EditText 跑掉
我在表格布局中有一个简单的标志,但里面的内容向右延伸得太远。在我看来,一切都是以中心为中心的。或者看起来 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>
I have a simple sign in tablelayout, but the contents inside are stretching too far to the right. Everything appears to me to be centered. Or it seems like the EditText is trying to center itself inside the main parent and not IT'S parent tablelayout. Any idea why?
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在两列表上遇到了同样的问题。
我在第二栏中的文字被从屏幕上截断了。
通过在我的
TableLayout
中使用android:shrinkColumns="1"
修复了该问题。这是我的代码,text3 太大并且被截断屏幕,直到我在
TableLayout
中添加shrinkColumns
属性。I had the same problem on a two column table.
My text in the second column was being cut off the screen.
Fixed it by using
android:shrinkColumns="1"
in myTableLayout
.Here's my code, text3 was too big and was being cut off the screen until I added the
shrinkColumns
attribute in myTableLayout
.您的表格布局的宽度设置为“wrap_content”,它的子级将其设置为“fill_parent”,没有一个人确切地知道任何事情:)将表格布局的宽度设置为“fill_parent”,所有内容都应该按照您的意思布局。
UPD
我在你的表中只看到一列。这意味着您可以安全地将其替换为垂直 LinearLayout。
Your table layout has it's width set to "wrap_content" and it's children have it at "fill_parent", not one of them knows anything exactly :) Set your table layout's width to "fill_parent" and everything should lay out as you mean it to.
UPD
I only see one column in your table. That means you can safely substitute it with vertical LinearLayout.
我遇到了同样的问题,网上的教程都没有帮助。最后,我发现设置表视图的“收缩列”属性就可以解决问题。
I had the same problem and none of the tutorials on the net were helpful. In the end , I found out setting the 'Shrink Columns' Property of the Table View would do the trick.
为EditText 外的列设置shrinkColumn 和stretchColumn。这为您提供了父级匹配宽度并且不会流失。
Set both shrinkColumn and stretchColumn for the column of running off EditText. This gives you a parent matching width and doesn't run off.
设置 EditTextView 的layout_width =“0dp”和layout_weight =“1”解决了我的问题。
Setting EditTextView's layout_width="0dp" and layout_weight="1" solved my problem.