Android XML layout problems

Associate
Joined
18 Feb 2010
Posts
940
Hi, i'm new to android, and i'm new to the layouts. I have programmed java for a year, but this is driving me nuts.

I'd really really really appreciate if someone could look at this code, and tell me what's wrong with it ( I think, probably a lot ). All I want is for one thing to work, i'm not too fussed ( although will greatly accept ) about lots of other problems.

I made this in eclipse, copy/pasting it there will show you the issue.

I gave one of the rows the ID "Textyline". I would like this to be the height of the text within it. How come, when I set it to "wrap_content", it makes every row have a larger than necessary height, and pushes off the screen everything after the first 4 rows? All I would like is to avoid having a large black space under the text "Trial Held", by having the linearLayout height fit the text.


I'd really appreciate some help with this, I understand what a pain it is to look at anyone elses code ( especially mine as i'm new to this ).

Thanks so much!

<?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">

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:mavity="center_horizontal"
android:background="#aa0000" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1" android:text="Credits: \n 2000"/>
<TextView android:text="green" android:mavity="center_horizontal"
android:background="#00aa00" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="blue" android:mavity="center_horizontal"
android:background="#0000aa" android:layout_height="fill_parent" android:layout_weight="1" android:layout_width="fill_parent"/>
<TextView android:text="yellow" android:mavity="center_horizontal"
android:background="#aaaa00" android:layout_height="fill_parent" android:layout_weight="1" android:layout_width="fill_parent"/>
<TextView android:text="yellow" android:mavity="center_horizontal"
android:background="#aa00aa" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1" />
</LinearLayout>

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">

<TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:mavity="center_horizontal" android:layout_weight="1" android:layout_gravity="center_horizontal" android:text="A1" android:textSize="15pt"/><TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="B1"/>
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="C1"/>
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="D1"/>
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="E1"/>


</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="A2"/>
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="B2"/>
<TextView android:text="C2" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView android:text="D2" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView android:text="E2" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />

</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="A3"/>
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="B3"/>
<TextView android:text="C3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView android:text="D3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView android:text="E3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />

</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="A3"/>
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="B3"/>
<TextView android:text="C3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent"/>
<TextView android:text="D3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView android:text="E3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:text="A3"/>



<Button android:id="@+id/Button03" android:text="Hold" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"></Button><Button android:id="@+id/Button04" android:text="Hold" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"></Button><Button android:id="@+id/Button05" android:text="Hold" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"></Button><TextView android:text="E3" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />

</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:id="@+id/TextView01" android:text="1" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView>
<TextView android:id="@+id/TextView08" android:layout_weight="1" android:text="2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView><TextView android:id="@+id/TextView07" android:layout_weight="1" android:text="3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView><TextView android:id="@+id/TextView06" android:layout_weight="1" android:text="4" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView><TextView android:id="@+id/TextView05" android:layout_weight="1" android:text="5" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView><TextView android:id="@+id/TextView04" android:layout_weight="1" android:text="6" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView><TextView android:id="@+id/TextView02" android:layout_weight="1" android:text="7" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView>
<TextView android:id="@+id/TextView03" android:text="8" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center"></TextView>
<TextView android:id="@+id/TextView09" android:text=" BONUS" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/Textyline" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent">
<TextView android:id="@+id/TextView01" android:text="Trial Held" android:layout_width="fill_parent" android:layout_gravity="center_horizontal" android:mavity="center" android:layout_height="wrap_content"></TextView>
</LinearLayout>

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textSize="7pt" android:layout_gravity="center_horizontal" android:mavity="center_horizontal" android:text="Net:"/><TextView android:id="@+id/wager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textSize="7pt" android:mavity="center_horizontal" android:layout_gravity="center_horizontal" android:text="Wager:"/><Button android:layout_width="wrap_content" android:text="-" android:layout_height="fill_parent" android:ellipsize="none" android:id="@+id/minus"></Button>
<Button android:layout_width="wrap_content" android:text="+" android:layout_height="fill_parent" android:id="@+id/plus"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:text="Gamble" android:layout_height="fill_parent" android:mavity="center_horizontal"></Button><Button android:id="@+id/Button01" android:mavity="center_horizontal" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="Spin"></Button>

</LinearLayout>
</LinearLayout>
 
Last edited:
If you dont want to use a different scheme, such as a RelativeLayout, play around with the 'weight' of Textyline. You can use the weight to determine how much relative screen space (or rather in this case, height) is assigned to your child LinearLayouts.

While the ideal solution is to specify precisely the height you need with wrap_content, iirc you can't really do that for a child of a LinearLayout.
 
Last edited:
Back
Top Bottom