Issue with Relative/Table Layout
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&g开发者_JS百科t;
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 a TableLayout
, then you need to have two TableRow
, one with the TextView
s and the other with the EditText
. Thus, the children of the TableLayout
will be the TableRow
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 three TextView
s that are above the each EditText
, and if you want them to be centered, then you can align both the left and the right side to the EditText
s.
I hope this helps, let me know what you think
精彩评论