Android Table (like) layout
Greetings all,
I'm trying to create a specific layout that should be very simple but having a very difficult time and was wondering if I could get some pointers.
The layout I'm looking for looks like this
Text label Text label Text Label
spinner Spinner Edit Text
The text labels and spinner columns should only take about 40% of the width total, and text label开发者_Go百科 and edit text should take the remaining 60%.
I tried using a table layout, but layout_weight doesn't seem to have any effect. The only way it seems I can set width is by hard coding the width of the items (android:width). Should I be using a table layout for this or 2 horizontal LinearLayouts? I'm wracking my mind here!
There are a lot of ways to do layouts in Android. You might consider nested LinearLayouts, whose orientation can be vertical or horizontal and you can assign layout_weight attributes to each element inside them. I don't believe layout_weight is valid outside of a LinearLayout, and so the best you can do in a TableLayout is setting the gravity. If I understand your intention correctly, you might try something like this:
<!-- this container holds everything -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- holds a text label and spinner -->
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<!-- TextView1 goes here -->
<!-- Spinner1 goes here -->
</LinearLayout>
<!-- another one of the same -->
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<!-- TextView2 goes here -->
<!-- Spinner2 goes here -->
</LinearLayout>
<!-- last column, with the label and edit text -->
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
>
<!-- TextView3 goes here -->
<!-- EditText1 goes here -->
</LinearLayout>
</LinearLayout>
You can find more information about LinearLayout (and RelativeLayout which is a good alternative for you) from http://developer.android.com/resources/tutorials/views/hello-linearlayout.html. Good luck!
Have you looked into Table Layout its basically what you needed
And quite a simple example goes here
精彩评论