I am trying to organize my view with the following view widgets -
- TextView (should fill the width of the screen and has a specific height)
- Custom View Drawn using Draw() (fill the width and should start after the above textview and fill the screen)
I am trying to write a board game and hence the custom view drawn.
My problem is what is best Layout to use for this?
Can I use a TableLayout and have these two views as one column each? I thought that would do the trick but which ever layout I use for the Custom View just does not fill the screen even though the tablerow I am drawing it in fills the screen.
I hope I was able to explain myself properly. Any pointers are greatly appreciated.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tl_question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2">
<TableRow>
<TextView
android:id="@+id/question"
android:layout_width="wrap_content"
android:textSize="30sp"
开发者_Go百科 android:textColor="#ffFFFFFF"
android:layout_gravity="center_vertical"
android:paddingBottom="9dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="2dip"/>
</TableRow>
<TableRow>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical" >
<com.ac.gui.CustomView
android:id="@+id/custom_board"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true" />
</LinearLayout>
</TableRow>
</TableLayout>
</RelativeLayout>
Try using this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="ASDFASDF"
android:textColor="#ffFFFFFF"
android:layout_gravity="center_vertical"
android:paddingBottom="9dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="2dip"/>
<com.ac.gui.CustomView
android:layout_below="@+id/question"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
I tested a different layout in place of yours and it works fine. It should work with yours as well.
RelativeLayout allows you to position items, well, relative to one another. You'll notice the attribute "layout_below" on your custom view where i specify the ID of the view to place it under.
精彩评论