相对/表格布局问题
我希望 TextView
始终位于所有设备屏幕上每个 EditText
的顶部。首先,我尝试使用 RelativeLayout
做一些事情,但它不起作用。现在,我正在尝试使用 TableLayout
。我想听听您对这种用途的最佳布局的意见!
这是我的代码:
<?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="fill_parent"
android:stretchColumns="2"
android:background="@drawable/back" >
<TextView android:id="@+id/mathimatika"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mathimatika Kateuthinsis"
android:textColor="#09074c"
android:textSize="14px"
android:gravity="center" />
<TableRow>
<TextView
android:layout_column="1"
android:text="Profwrika a"
android:padding="13dip"
android:textColor="#09074c"
android:textSize="10px"/>
<TextView
android:text="Profwrika b"
android:gravity="center"
android:textColor="#09074c"
android:textSize="10px" />
<TextView
android:text="grapta"
android:gravity="right"
android:padding="13dip"
android:textColor="#09074c"
android:textSize="10px" />
</TableRow>
<RelativeLayout>
<EditText
android:id="@+id/input11"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_below="@id/vathmos1"
android:layout_marginLeft="13dip" />
<EditText
android:id="@+id/input21"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_toRightOf="@id/input11"
android:layout_below="@id/vathmos1"
android:layout_marginLeft="25px" />
<EditText
android:id="@+id/input31"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_toRightOf="@id/input21"
android:layout_below="@id/vathmos1"
android:layout_marginLeft="25px" />
</RelativeLayout>
</TableLayout>
I want the TextView
to be always on the top of each EditText
, on all of device's screens. First, I've tried to do something with RelativeLayout
, but it's not working. Now, I'm trying with TableLayout
. I would like your opinion for the best layout for this use!
Here is my code:
<?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="fill_parent"
android:stretchColumns="2"
android:background="@drawable/back" >
<TextView android:id="@+id/mathimatika"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mathimatika Kateuthinsis"
android:textColor="#09074c"
android:textSize="14px"
android:gravity="center" />
<TableRow>
<TextView
android:layout_column="1"
android:text="Profwrika a"
android:padding="13dip"
android:textColor="#09074c"
android:textSize="10px"/>
<TextView
android:text="Profwrika b"
android:gravity="center"
android:textColor="#09074c"
android:textSize="10px" />
<TextView
android:text="grapta"
android:gravity="right"
android:padding="13dip"
android:textColor="#09074c"
android:textSize="10px" />
</TableRow>
<RelativeLayout>
<EditText
android:id="@+id/input11"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_below="@id/vathmos1"
android:layout_marginLeft="13dip" />
<EditText
android:id="@+id/input21"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_toRightOf="@id/input11"
android:layout_below="@id/vathmos1"
android:layout_marginLeft="25px" />
<EditText
android:id="@+id/input31"
android:layout_width="60px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="decimal|signed"
android:layout_toRightOf="@id/input21"
android:layout_below="@id/vathmos1"
android:layout_marginLeft="25px" />
</RelativeLayout>
</TableLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你可以用
RelativeLayout
来做到这一点,我不明白你为什么说你不能这样做。但如果您想将其与TableLayout
一起使用,那么您需要有两个TableRow
,一个带有TextView
,另一个带有编辑文本
。因此,TableLayout
的子级将是TableRow
。但是,我建议您使用RelativeLayout,它更便宜,因为它不需要计算内容并且它在堆栈中只有一层。
您可以首先定义三个
EditText
,然后定义每个EditText
上方的三个TextView
,如果您希望它们居中,然后您可以将左侧和右侧与EditText
对齐。我希望这有帮助,让我知道你的想法
Well, you can do it with a
RelativeLayout
, I dont understand why you say you cant do it. But if you want to use it with aTableLayout
, then you need to have twoTableRow
, one with theTextView
s and the other with theEditText
. Thus, the children of theTableLayout
will be theTableRow
s.However, I would recommend that you use a RelativeLayout, its cheaper because it doesnt have to calculate stuff and its only one level in the stack.
You can define your three
EditText
first, then the threeTextView
s that are above the eachEditText
, and if you want them to be centered, then you can align both the left and the right side to theEditText
s.I hope this helps, let me know what you think