I have a layout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fsfsdfds"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fdsfdsfds"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
It fill the whole space of the activity.
How can I make these 2 TextViews and EditTexts take only space enough to show themselves (not fill all the space) and align the button to the bottom?
I think this is what you're looking for :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView1" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/LinearLayout1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView2" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
EDIT :
If you don't want to use the two LinerLayouts (and therefore gain even more performance), you can do the following :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/EditText1"
android:layout_gravity="center_vertical"
android:text="TextView1" />
<EditText
android:id="#+id/EditText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:layout_toEndOf="#id/TextView1"
android:layout_toRightOf="#id/TextView1"
android:inputType="text" />
<TextView
android:id="#+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/EditText2"
android:layout_below="#id/TextView1"
android:layout_gravity="center_vertical"
android:text="TextView2" />
<EditText
android:id="#+id/EditText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/EditText1"
android:layout_gravity="center_vertical"
android:layout_toEndOf="#id/TextView2"
android:layout_toRightOf="#id/TextView2"
android:inputType="text" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
Check This.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:text="fsfsdfds" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:text="fdsfdsfds" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
You try with RelativeLayout, or else if wanted to be done with LinearLayout you need to consider weights if width is not fillparent.
Check below sample to start with ..
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:text="fsfsdfds" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.8" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:text="fdsfdsfds" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.8" />
Either convert to a relative-layout and use alignparentbottom for the button - or use layout weights for the linear-layouts
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.
I'm trying to get two linear layout side by side and put content inside of it.
I want the two linear layouts to be side by side, but the left one should take about 3/4 of the screen and the right one the rest of it.
This is my code: https://gitlab.com/snippets/1682040
But the two linear layouts always change the width and the height depending on the content.
How can I have two linear layouts side by side with fixed width and height?
A better solution with RelativeLayout is always welcome.
This is the result:
Use layout_weight property of LinearLayout and android:weightSum property for parent layout.
Do Something like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75" // For First layout to 3/4
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical">
//First Layout content Here
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25" // For Second layout to rest of screen
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
//Second Layout Content Here
</LinearLayout>
</LinearLayout>
I know that you asked for a solution with the LinearLayout but I suggest you to solve this problem with the ConstraintLayout. You will get incredible performance improvements without nested view.
In this sample I added a vertical guideline at 75% of from the left of the screen. I have only to remove the nested LinearLayouts and add the constraints to your views!
Try it out!
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="628dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"
android:textSize="20dp" />
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="AAAAA"
android:textColor="#color/gray"
android:textSize="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="628dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline4"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue" />
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/lightGray" />
</LinearLayout>
<android.support.constraint.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.75" />
Try this give Your first LinearLayout android:layout_weight=".75" so it can take 3/4 space in screen
than assign android:layout_weight="0.25" to Your second LinearLayout so it can take remaining space
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:background="#color/colorPrimary"
android:orientation="vertical">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/colorBlue"
android:textSize="20dp" />
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="AAAAA"
android:textColor="#color/colorGreen"
android:textSize="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/colorPrimary"
android:textSize="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/colorPrimary"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/colorBlue" />
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/colorRed" />
</LinearLayout>
</LinearLayout>
Seems like both of the weights are set to "1". Have you tried ".5"?
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_weight="0.50"
android:gravity="left|center">
Try this I have added weight
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75"
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"
android:textSize="20dp" />
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="AAAAA"
android:textColor="#color/gray"
android:textSize="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue" />
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/lightGray" />
</LinearLayout>
</LinearLayout>
First remove weightSum attribute from parent layout.
If you want your first layout to be 3/4 of you should put weight 0.75 and 0.25 (1/4) for the other one like here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_weight=".75"
android:layout_gravity="left"
android:gravity="left|center">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"
android:textSize="20dp"/>
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:text="AAAAA"
android:textColor="#color/gray"
android:textSize="15dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera"/>
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera"
android:layout_marginLeft="15dp"/>
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_weight=".25"
android:gravity="center">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"/>
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/lightGray"/>
</LinearLayout>
try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000"
android:textSize="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_txt"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000"
android:textSize="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_txt"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
Change the weight sum to 4 in the parent layout and add weight as 3 for child linear layout so it can take 3/4 space and 1 to child linear layout so that it will take the remaining space.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical">
//Your contents
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
//Your contents
</LinearLayout>
</LinearLayout>
I have a LinearLayout with like a contact form for the user to edit his profile. However, the size of the editText just doesn't change no matter what size I give to the layout_weight. Tyvm for any help!
<?xml version="1.0" encoding="utf-8"?>
<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:background="#color/first_grey"
android:orientation="vertical"
tools:ignore="ContentDescription">
<include
android:id="#+id/tool_bar"
layout="#layout/toolbar_all_activities" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/viewUploadPicture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="25"
android:layout_marginTop="20dp"
android:clickable="true"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgUserProfile"
android:layout_width="0dp"
android:layout_height="90dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:src="#drawable/skate_boarder" />
<TextView
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_weight="0.5"
android:gravity="center_vertical|start"
android:text="#string/user.edit.upload_photo"
android:textColor="#color/fourth_grey"
android:textSize="18sp" />
</LinearLayout>
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.first_name" />
<EditText
android:id="#+id/txtEditProfileFirstName"
style="#style/editTextRoundGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" />
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.last_name" />
<EditText android:id="#+id/txtEditProfileLastName"
style="#style/editTextRoundGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" />
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.edit.favourite_hobby" />
<EditText
android:id="#+id/txtEditProfileFavouriteHobby"
style="#style/editTextRoundGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" />
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.edit.birthday_date" />
<LinearLayout
android:id="#+id/birthdayLayout"
android:layout_width="300dp"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="50"
android:orientation="horizontal">
<EditText
android:id="#+id/txtDayBirthdayDate"
style="#style/editTextNumberRoundGrey"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2" />
<EditText
android:id="#+id/txtMonthBirthdayDate"
style="#style/editTextNumberRoundGrey"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight="0.2" />
<EditText
android:id="#+id/txtYearBirthdayDate"
style="#style/editTextNumberRoundGrey"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight="0.5" />
</LinearLayout>
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.edit.bio" />
<EditText
style="#style/editTextRoundGreyBigger"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="120" />
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.edit.city" />
<EditText
android:id="#+id/txtEditProfileCity"
style="#style/editTextRoundGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" />
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.edit.languages" />
<EditText
android:id="#+id/txtEditProfileLanguages"
style="#style/editTextRoundGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" />
<TextView
style="#style/editProfileTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="40"
android:text="#string/user.edit.password" />
<EditText
android:id="#+id/txtEditProfilePass"
style="#style/editTextRoundGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" />
<Button
android:id="#+id/btnSubmitChangedData"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:layout_weight="100"
android:padding="10dp"
android:background="#color/red"
android:text="#string/user.edit.submit" />
</LinearLayout>
</ScrollView>
</LinearLayout>
you can't use layout_weight in ScrollView because it depend on the height of the child layout and layout_weight too depend on the height of the outside layout and that's contradiction, so you can use custom layout_height to every child .
I know the answer is late but i hope it help someone else .
The android:layout_weight attribute is used in conjunction with the android:weightSum attribute. Your children layout_weights must sum to the weightSum of their parent layout.
You use layout_weight many times in your xml code without declaring a weightSum. Without android:weightSum, android:layout_weights will have no effect. For instance, if you want two views within a parent LinearLayout to span evenly, you can do something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<EditText
android:id="#+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:hint="type something">
<Button
android:id="#+id/my_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:text="a button">
</LinearLayout>
Note that your child views' layout_heights will need to be set to "0dp" for vertical LinearLayout orientation. For a horizontal orientation, you'd set the child views' layout_widths to "0dp".
For another example, see the accepted answer at https://stackoverflow.com/a/7452788/4138919
I also notice that you mix floating point values with non-floating point values for layout_weights. Consider sticking to one or the other for readability purposes.
For changing Edittext height you should also prefer to use attributes like maxHeight, minHeight, maxLines, inputTypes, and textAppreance attributes,
This below example might help you :
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:ignore="ContentDescription">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:paddingLeft="5dip"
android:paddingRight="5dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="FirstName" />
<!-- Person Name EditText-->
<EditText
android:id="#+id/txtEditProfileFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="40dip"
android:inputType="textPersonName"
android:maxLines="1"
android:maxLength="25"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="LastName" />
<EditText android:id="#+id/txtEditProfileLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="40dip"
android:inputType="textPersonName"
android:maxLines="1"
android:maxLength="25"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Hobby" />
<EditText
android:id="#+id/txtEditProfileFavouriteHobby"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="40dip"
android:inputType="text"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Birthday Date" />
<LinearLayout
android:id="#+id/birthdayLayout"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:weightSum="1"
android:orientation="horizontal">
`enter code here` <EditText
android:id="#+id/txtDayBirthdayDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:inputType="number"
android:gravity="center"
android:layout_gravity="center"
android:maxLength="2"
/>
<EditText
android:id="#+id/txtMonthBirthdayDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight="0.3"
android:gravity="center"
android:layout_gravity="center"
android:inputType="number"
android:maxLength="2"
/>
<EditText
android:id="#+id/txtYearBirthdayDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight="0.4"
android:inputType="number"
android:gravity="center"
android:layout_gravity="center"
android:maxLength="4"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Bio" />
<!--MultiLine EdiText-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minHeight="80dp"
android:maxLines="4"
android:isScrollContainer="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="City"
/>
<EditText
android:id="#+id/txtEditProfileCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="40dip"
android:inputType="textPostalAddress"
android:maxLines="1"
android:maxLength="25"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Languages" />
<EditText
android:id="#+id/txtEditProfileLanguages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="40dip"
android:inputType="text"
android:maxLines="1"
android:maxLength="25"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="password" />
<!--Password EditText-->
<EditText
android:id="#+id/txtEditProfilePass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="40dip"
android:inputType="textPassword"
android:maxLines="1"
android:maxLength="25"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:id="#+id/btnSubmitChangedData"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:padding="10dp"
android:background="#color/red"
android:text="Submit" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Based on how XAML works, I thought I could give my android widgets a percentage value for width. After searching, I found that *theoretically," this is available via the "layout_weight" property. But using this does not produce the desired appearance. Specifically, this xml:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".40"
android:entries="#array/delivery_upcplu_spinner" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".90"
android:editable="false" />
</LinearLayout>
</LinearLayout>
...gives me this:
I can brute-force the layout to look more-or-less as I want it using explicit width values, like so:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="160dp"
android:layout_height="40dp"
android:entries="#array/delivery_upcplu_spinner" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="200dp" />
</LinearLayout>
</LinearLayout>
...which looks like this:
...but doing this (assigning specific dp vals to the width) makes me more nervous than a cat in a roomful of rocking chairs.
Is there balsam in Gilead? I mean, is there, after all, a way to assign percentage widths (that actually works, of course)?
Am I using layout_weight wrong, or am I using the wrong methodology, or is it (perish the thought) impossible?
UPDATE
The accepted answer worked in one instance, but in the next:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/pack_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextPackSize"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
</LinearLayout>
...it doesn't:
It takes up half the width instead of all of it; must I put some "replace" talk in the EditText widgets for them to "widen out"?
I can "force it" by adding to the EditTexts:
android:minWidth="120dp"
...but that returns me to the nervosity level of the rocking-chair-room cat.
UPDATE 2
Now even what I thought was working is not, or no longer. The xml is this:
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="4dp"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="hhs.app.DeliveryActivity">
<!--Row 0-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:maxWidth="12dp"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".90"
android:minWidth="1200dp"
android:editable="false"
/>
</LinearLayout>
<!--Row 1-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextID"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/pack_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextPackSize"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
</LinearLayout>
</LinearLayout>
...and it looks like this:
IOW, in the first row, the EditText is getting scrunched like a svelte trainer by an age-old elephant, and in the next row, the attempted equality of widths is not being observed (although it actually looks fine, those labels are not taking one-quarter of the width, but only what they need and no more).
And, the same is the case when I change ".25" to either "0.25" or "1" in all cases.
UPDATE 3
Okay, here is what I see with my LinearLayout with various combinations of "match_parent" and "wrap_content" for its "layout_width" and "layout_height" properties.
When both are set to wrap_content:
When both are set to match_parent:
If width is set to match_parent, and height is set to wrap_content, it is the same as when BOTH are set to match_parent
The other way around (with height set to match_parent and width set to wrap_content), it is the same as when BOTH are set to wrap_content
UPDATE 4
Here is the entire contents of this particular layout file, at its best, albeit not perfect by any means:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="4dp"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="hhs.app.DeliveryActivity">
<!--Row 0-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:maxWidth="12dp"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".90"
android:minWidth="1200dp"
android:editable="false"
/>
</LinearLayout>
<!--Row 1-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="#string/id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextID"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight="25" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="#string/pack_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextPackSize"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight="25" />
</LinearLayout>
</LinearLayout>
<!--Row 2-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/desc"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="320dp" />
</LinearLayout>
</LinearLayout>
<!--Row 3-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="144dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/count"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="144dp" />
</LinearLayout>
</LinearLayout>
<!--Row 4-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cost"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editCost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/margin"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextMargin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/list"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
</LinearLayout>
<!--Row 5-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dept"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinnerDept"
android:layout_width="180dp"
android:layout_height="40dp"
android:entries="#array/departments" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextDollar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
</LinearLayout>
<!--Row 6-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sub_dept"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinnerSubdept"
android:layout_width="248dp"
android:layout_height="40dp"
android:entries="#array/subdepartments" />
</LinearLayout>
</LinearLayout>
<!--Row 7-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/box"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery_invoice_number"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextDelivInvNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="124dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vendor"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextVendor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="124dp" />
</LinearLayout>
</LinearLayout>
<!--Row 8-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/total_dollars"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextTotalDollars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_total"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextCurrentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextReadonlyQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="40dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--Row 9-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save" />
<Button
android:id="#+id/buttonFind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/find" />
<Button
android:id="#+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clear" />
</LinearLayout>
</LinearLayout>
</ScrollView>
UPDATE 5
Okay, what I'm getting out of this is that the internal-most LinearLayouts need to be thus:
android:layout_width="match_parent"
android:layout_height="wrap_content"
...and all others (above them) thus:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
That works for the most part. But the EditTexts are too puny. If I remove the inner LinearLayouts completely, the EditTexts disappear (or have dimensions of 0?)
You should have a single LinearLayout containing all the "weighted" widgets.
Note that only 1 dimension at a time can be "weighted":
This is how I'd do that:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".40"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".60"
android:editable="false"
/>
</LinearLayout>
Note that the weight sum is 1 (android calculates it by itself).
I could set 4 and 6 or 40 and 60 - for Android that's always 100%, when summed.
You can optionally set a weightSum attribute in the Containing LinearLayout:
android:weightSum="1"
(or 10, or 100, ...)
If you want to (and your layout isn't complex), you can weight the other "dimension" (height in this case), too.
Just add another LinearLayout containing another Spinner and EditText.
Then enclose these 2 LinearLayouts in a third one.
Give both the children LinearLayouts a weight of 1 and a height of 0dp, so they will equally divide the container's height.
Some thing like that:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:editable="false"
/>
</LinearLayout>
or
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="70"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30"
android:editable="false"
/>
</LinearLayout>
Dear All experts I have problem with using scrollView anyone please help.. the Error is showing that the ScrollView is useless and also in other form of mine is shows the same , how can I solve this and how can I make my forms and activities been scroll ??
`
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="#string/welcome"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:contentDescription="#+id/button1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="android:buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goToMain"
android:text="#string/log_in" />
<Button
android:id="#+id/button2"
style="android:buttonStyle "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="#string/registration" />
</LinearLayout>
</ScrollView>
`
You need a child container as LinearLayout, TableLayout or RelativeLayout in your ScrollView like this:
<ScrollView
... >
<LinearLayout
... >
<!-- Your views: TextView, LinearLayout, etc. -->
</LinearLayout>
</ScrollView>
According to the reference:
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll
You should put all the other fields in a single Layout.. Like linear layout,relative layout. Your whole code should look like this
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="#string/welcome"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:contentDescription="#+id/button1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="android:buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goToMain"
android:text="#string/log_in" />
<Button
android:id="#+id/button2"
style="android:buttonStyle "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="#string/registration" />
</LinearLayout>
</LinearLayout>
</ScrollView>
"Scrollview can host only one direct child"
Put all your stuff in some Layout e.g LinearLayout