In my layout I have two different LinearLayouts. The first one is this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center"
android:text="#string/lblPais" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblJ" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblG" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblP" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPC" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblDif" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPuntos" />
</LinearLayout>
And the second one is this layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="15" >
<TextView
android:id="#+id/lblPais1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center"
android:text="#string/lblPais" />
<TextView
android:id="#+id/lblJ1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblG1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblP1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblPF1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblPC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblDif1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPtsVacio" />
<TextView
android:id="#+id/lblPuntos1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPtsVacio" />
</LinearLayout>
As you can see both layouts get the same value for the layout_width attribute (match_parent). Inside both layouts I have the same number of elements (8 TextView). Each TextView has the same weight except the first one, that has a weight of 8.
If both layouts are the same (only differ the label on the TextViews) why do they have different sizes?
Try this way,hope this will help you to solve your problem.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center"
android:text="#string/lblPais" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblJ" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblG" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblP" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPF" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPC" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblDif" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPuntos" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblPais1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center"
android:text="#string/lblPais" />
<TextView
android:id="#+id/lblJ1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblG1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblP1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblPF1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblPC"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lbl0" />
<TextView
android:id="#+id/lblDif1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPtsVacio" />
<TextView
android:id="#+id/lblPuntos1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lblPtsVacio" />
</LinearLayout>
</LinearLayout>
if you want all layout to be same as your weight
your orientation is vertical so change...
android:layout_height="wrap_content"
to
android:layout_height="0dp"
In all TextView
You havent given android:weightSum="15" in first linear layout.
You have to add andoid:weightSum="15" on the first parent layout and everything should fall into place.
Make your parent linear layout height as
android:layout_height="match_parent"
Related
Hi, I make application with this Image.
I want place the text on red dot points at lines left side and right side.
So I place the text on point, but when I change the device Galaxy S6 to S8,
text placement depart from lines.
I seperate the lines and put weight on it, but still out.
How I can place the text on that image in variable device?
Please help me.
This is my layout.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="#drawable/nursecategory"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!--first line-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="32dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textColor="#color/colorCategory"
android:textStyle="bold"
android:layout_alignParentRight="true"
/>
<TextView
android:id="#+id/nursetree_textview_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
</LinearLayout>
<!--second line-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="24dp"
>
<!--Name-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Agency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<!--width-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Width"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Width"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
</LinearLayout>
<!--third line-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="26dp"
>
<!--place-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Place"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<!--heigth-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Height"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
use Relativelayout as parent layout then try to design your view.
in Relaytivelayout we can add layouts as tray. and it easily to handle.
also read about Relativlayout.
Here in above screen shot it just looking fine and full screen only on my Eclips(Graphic Layout), but when i run it on my real device , then it show padding from top Right and Left as below screenshot. i just want it should same display on my real device as display above in (Graphic layout)
Above is a screenshot. Below is my xml code. You can see in screenshot that the xml design is not showing as fullscreen. I want to show fullscreen all my items What am I missing?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4"
tools:context="selection.detail.Selection_datail_adapter" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:orientation="vertical"
android:weightSum="5" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_bettypeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_bettype"
android:textColor="#FFFDFE"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_betTypeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_detailCourseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_course"
android:textColor="#FFFDFE"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_courseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_detailtimeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_time"
android:textColor="#FFFDFE"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_timeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_detail_stackID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<!-- android:autoLink="web"-->
<TextView
android:id="#+id/txt_detailurlID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Best Odds Available At"
android:textColor="#0733F5" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txt_name_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_horse" />
<TextView
android:id="#+id/txt_detail_horseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txt_total_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_odds" />
<TextView
android:id="#+id/txt_detail_fractionID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txt_proofinglink_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_decimal" />
<TextView
android:id="#+id/txt_detail_decimalID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView" />
</LinearLayout>
Any help is appreciated.
You're missing padding/margins in one of the containers: ListView/RecyclerView, fragment layout, activity layout,please remove padding from listviews layout
I am not into providing the exact codes, but your xml layout needs to be modified a lot. Too much nesting of LinearLayouts (do avoid that next time). I think you also missed putting the actual TextViews. But I think if you modify the xml below, you'll get your desired behavior.
Here's the xml (I modified it from the one you posted):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_bettypeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Bet Type"
android:textColor="#FFFDFE"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_betTypeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="Each Way"
android:textColor="#FFFDFE" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_detailCourseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Detail Course"
android:textColor="#FFFDFE"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_courseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="NEW CASTLE (A.W)"
android:textColor="#FFFDFE" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_detailtimeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Detail Time"
android:textColor="#FFFDFE"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_timeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="16:15"
android:textColor="#FFFDFE" />
</RelativeLayout>
<TextView
android:id="#+id/txt_detail_stackID"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:text="E/W Stake of 0.5pt(s) for a Total Stake of 1.00pts"
android:textColor="#FFFDFE" />
<!-- android:autoLink="web"-->
<TextView
android:id="#+id/txt_detailurlID"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:text="Best Odds Available At William Hill"
android:textColor="#0733F5" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/txt_name_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Horse" />
<TextView
android:id="#+id/txt_detail_horseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="Nakeeta" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/txt_total_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Odds Fraction" />
<TextView
android:id="#+id/txt_detail_fractionID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="9/1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/txt_proofinglink_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Odds Decimal" />
<TextView
android:id="#+id/txt_detail_decimalID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="10.00" />
</RelativeLayout>
</LinearLayout>
Here's the screenshot:
Cheers!
here is your answer
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4"
tools:context="selection.detail.Selection_datail_adapter" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_weight="1"
android:background="#B2B2B2"
android:orientation="vertical"
android:weightSum="5" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_bettypeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_bettype"
android:textColor="#FFFDFE"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_betTypeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_detailCourseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_course"
android:textColor="#FFFDFE"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_courseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_detailtimeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_time"
android:textColor="#FFFDFE"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_detail_timeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_detail_stackID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="TextView"
android:textColor="#FFFDFE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<!-- android:autoLink="web"-->
<TextView
android:id="#+id/txt_detailurlID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Best Odds Available At"
android:textColor="#0733F5" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TextView
android:id="#+id/txt_name_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_horse" />
<TextView
android:id="#+id/txt_detail_horseID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<TextView
android:id="#+id/txt_total_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_odds" />
<TextView
android:id="#+id/txt_detail_fractionID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TextView
android:id="#+id/txt_proofinglink_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/str_detail_decimal" />
<TextView
android:id="#+id/txt_detail_decimalID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
This question already has answers here:
How can I avoid "IllegalStateException: Scrollview can host only one direct child"?
(7 answers)
Closed 9 years ago.
I have multiple LinearLayouts with a combined height that easily exceeds a device's screen height. So in order to make my layout scrollable, I tried adding in a ScrollView, but unfortunately I get the following error:
Scrollview can host only one direct child
I did some research, but couldn't really make sense of how to solve it, even after reading a couple of solutions. I tried a few changes, but nothing worked for me so far. Any help?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dip">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 1"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q1_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 2"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q2_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 3"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q3_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 4"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q4_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 5"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q5_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 6"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q6_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 7"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q7_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 8"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q8_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 9"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q9_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 10"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q10_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 11"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q11_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 12"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q12_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 13"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q13_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 14"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q14_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 15"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q15_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 16"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q16_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 17"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q17_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 18"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q18_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 19"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q19_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 20"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/q20_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Score:"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="#+id/final_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0/5"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Wrap all the children inside of another LinearLayout with wrap_content for both the width and the height as well as the vertical orientation.
I'm trying to build a grid with some linear layouts.
Unfortunately the buttons inside the "grid" fill all the space and the "grid" isn't always the same size.
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/banner"
android:background="#80000000"
android:contentDescription="#string/about"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="#string/modi1"
tools:context=".MenuActivity" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="#string/modi2"
tools:context=".MenuActivity" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="10dp"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_diagramm" />
<Button
android:layout_marginTop="10dp"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_countdown" />
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_diagramm" />
<Button
android:layout_marginTop="10dp"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_countdown" />
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_diagramm" />
<Button
android:layout_marginTop="10dp"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/szen_countdown" />
</LinearLayout>
</LinearLayout>
</ScrollView>
It should look something like
this
with the buttons centered and at the size they need with the text inside.
Could anyone help me?
Try this.
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#80000000"
android:contentDescription="ImageView"
android:layout_span="2"
android:src="#drawable/banner" />
</TableRow>
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="modi1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="modi2" />
</TableRow>
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_diagramm" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_countdown" />
</TableRow>
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_diagramm" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_countdown" />
</TableRow>
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_diagramm" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:gravity="center"
android:text="szen_countdown" />
</TableRow>
</TableLayout>
this is how it shows to me
Remove the android:layout_weight="1" to avoid the button filling all the space.
You should try using a TableLayout and several TableRow to replace your LinearLayouts containing the buttons, thus creating a well formated grid
I had a similar problem, solved inserting a LinearLayout in TableRow. Have a look to the posted xml code and verify if it fits your requirements.
<TableRow
android:layout_gravity="fill_horizontal"
android:paddingTop="#dimen/table_row_padding_top" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageButton
android:contentDescription="#string/str_phone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/icon_phone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:text="#string/str_phone"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/icon_car"
android:contentDescription="#string/str_car" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:text="#string/str_car"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
I have LinearLayouts nested in a "Master Layout" with their width set to fill_parent and height to 0dp.
The Master has a weight sum of 100 and a vertical orientation, and I have the nested layouts with their respective weights. The goal is to split the vertical space, but they all disappear. What am I doing wrong?
Here is the XML, I have only applied the weight/layouts to the top few.
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:id="#+id/LinearLayout03"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="20" >
<ImageView
android:id="#+id/terranlogo1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/terranlogo" />
<ImageView
android:id="#+id/protosslogo1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="0dp"
android:src="#drawable/protosslogo" />
<ImageView
android:id="#+id/zerglogo1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/zerglogo" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout04"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5" >
<CheckBox
android:id="#+id/ck_t1"
android:layout_width="0dp"
android:layout_height="0dp" />
<CheckBox
android:id="#+id/ck_p1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="25dp" />
<CheckBox
android:id="#+id/ck_z1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="25dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout05"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5" >
<ImageView
android:id="#+id/terranlogo2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/terranlogo" />
<ImageView
android:id="#+id/protosslogo2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/protosslogo" />
<ImageView
android:id="#+id/zerglogo2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/zerglogo" />
</LinearLayout>
<CheckBox
android:id="#+id/ck_t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="#+id/ck_p2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp" />
<CheckBox
android:id="#+id/ck_z2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="18dp"
android:layout_marginTop="17dp"
android:gravity="center_vertical|center_horizontal"
android:text="Choose your opponets race(s) and your race(s)"
android:textSize="30dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Game Length"
android:textSize="15dp" />
<Spinner
android:id="#+id/s_answertime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Mistakes Allowed"
android:textSize="15dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer Time"
android:textSize="15dp" />
<Spinner
android:id="#+id/s_mistakenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Spinner
android:id="#+id/s_gametime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
This is the way how to split available space evenly
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="horizontal" >
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1.0">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="horizontal" >
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text3"/>
</LinearLayout>
</LinearLayout>