Evenly distribute elements on screen - android

I want to evenly distribute the elements "checkbox, desayuno,elegir hora" to the full width of the screen.After the "elegir hora" button there is a small
Textview where the chosen time is shown, but very small. I have tried setting android:layout_weight="1" but it didn't work.this is how it is displayed:screenshot
Heres the layout code:
<?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="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/nombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nombre de la pastilla"
android:gravity="center|center"
/>
<EditText
android:id="#+id/nombrePastilla"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:background="#color/color_blanco"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBoxDesayuno"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Desayuno"
android:layout_weight="1"
/>
<Button
android:id="#+id/buttonDesayuno"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Elegir hora"
android:layout_weight="1"
/>
<TextView
android:id="#+id/horaDesayuno"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text=""
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBoxComida"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Comida"
/>
<Button
android:id="#+id/buttonComida"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Elegir hora" />
<TextView
android:id="#+id/horaComida"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text=""
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBoxCena"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Cena" />
<Button
android:id="#+id/buttonCena"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Elegir hora" />
<TextView
android:id="#+id/horaCena"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text=""
/>
</LinearLayout>
<Button
android:id="#+id/finalizar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Finalizar" />
</LinearLayout>

//You have to give weightsum to linear layout and layoutweight to your textview
and checkbox(Simply copy and paste this)
<?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="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/nombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|center"
android:text="Nombre de la pastilla" />
<EditText
android:id="#+id/nombrePastilla"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<CheckBox
android:id="#+id/checkBoxDesayuno"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:text="Desayuno" />
<Button
android:id="#+id/buttonDesayuno"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:text="Elegir hora" />
<TextView
android:id="#+id/horaDesayuno"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="start|center_vertical"
android:text="dmeo"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<CheckBox
android:id="#+id/checkBoxComida"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:text="Comida"
/>
<Button
android:id="#+id/buttonComida"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:text="Elegir hora" />
<TextView
android:id="#+id/horaComida"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="start|center_vertical"
android:text="dmeo"
android:textSize="18dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<CheckBox
android:id="#+id/checkBoxCena"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:text="Cena" />
<Button
android:id="#+id/buttonCena"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:text="Elegir hora" />
<TextView
android:id="#+id/horaCena"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="start|center_vertical"
android:text="dmeo"
android:textSize="18dp"
/>
</LinearLayout>
<Button
android:id="#+id/finalizar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Finalizar" />

Related

How to make TextView fill space vertically in ScrollView?

I have following layout. I have FrameLayout (fuchsia) filling entire screen and on the left I have ScrollView (silver). In ScrollView is LinearLayout (lime) with buttons. Above bottom button is TextView spacer. I want it to fill vertical space so that bottom button is at the bottom of screen. With scroll view scrolling works but spacer is not stretched:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00ff">
<ScrollView
android:layout_width="134dp"
android:layout_height="match_parent"
android:background="#aaaaaa">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ff00"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Top" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="7" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Spacer" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom" />
</LinearLayout>
</ScrollView>
</FrameLayout>
If I remove ScollView then spacer is stretched but scrolling doesn't work in landscape mode:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00ff">
<LinearLayout
android:layout_width="134dp"
android:layout_height="match_parent"
android:background="#00ff00"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Top" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="7" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Spacer" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom" />
</LinearLayout>
</FrameLayout>
Solution:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00ff">
<ScrollView
android:layout_width="134dp"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#aaaaaa">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ff00"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Top" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="7" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Spacer" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom" />
</LinearLayout>
</ScrollView>
</FrameLayout>
Setting android:fillViewport="true" on the ScrollView fixed your issue and setting the height of ScrollView to match_parent.
I think constraint layout will help you.
<ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="134dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/btnBottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="134dp"
android:layout_height="wrap_content"
android:background="#00ff00"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Top" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="7" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Spacer" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/btnBottom"
android:layout_width="134dp"
android:layout_height="wrap_content"
android:text="Bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintLayout>

My ListView is hiding behind my parent layout when visibility is set to View.GONE

I am trying to set my list view when I click on image, it should be hidden or shown but the problem is that when I inflate my list view in my activity, it is hiding behind and not taking complete space. When I perform on click event it opens behind the parent layout.
SNAPSHOT
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
tools:context="com.bitblue.dextronewproject.Avtivity.ReportActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/main_linear_layout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Fees History"
android:textSize="20sp"
android:typeface="monospace" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="5dp"
android:background="#color/studentlogin" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Receipt"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date"
android:typeface="monospace" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_2"
android:layout_below="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TableLayout
android:id="#+id/r_tablelayoutRAD"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
</TableLayout>
<ImageView
android:id="#+id/drop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5.5"
android:src="#drawable/ic_drop_down_round_button" />
</LinearLayout>
<ListView
android:layout_below="#id/ll_2"
android:id="#+id/lisstview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Unpaid"
android:textSize="20sp"
android:typeface="monospace" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="30dp"
android:text="Type"
android:textSize="15dp"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="30dp"
android:text="Amount"
android:textSize="15dp"
android:typeface="monospace" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="5dp"
android:background="#color/studentlogin" />
<ListView
android:layout_width="match_parent"
android:id="#+id/un_paid_list_view"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</RelativeLayout>
Your effort is appreciable.Thanks in andvance
Your parent layouts are not matching. You have used layout_below in LinearlLayout where the parent is not RelativeLayout. Check the hierarchy of the layouts in your layout.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
tools:context="com.bitblue.dextronewproject.Avtivity.ReportActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Fees History"
android:textSize="20sp"
android:typeface="monospace"
android:id="#+id/textView1"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="5dp"
android:background="#color/studentlogin"
android:layout_below="#+id/textView1"
android:id="#+id/view1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/view1"
android:id="#+id/ll1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Receipt"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date"
android:typeface="monospace" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_2"
android:layout_below="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TableLayout
android:id="#+id/r_tablelayoutRAD"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
</TableLayout>
<ImageView
android:id="#+id/drop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5.5"
android:src="#drawable/ic_drop_down_round_button" />
</LinearLayout>
<ListView
android:layout_below="#+id/ll_2"
android:id="#+id/lisstview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Unpaid"
android:textSize="20sp"
android:typeface="monospace"
android:layout_below="#+id/lisstview"
android:id="#+id/textView2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/textView2"
android:id="#+id/ll3">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="30dp"
android:text="Type"
android:textSize="15dp"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="30dp"
android:text="Amount"
android:textSize="15dp"
android:typeface="monospace" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="5dp"
android:background="#color/studentlogin"
android:layout_below="#+id/ll3"
android:id="#+id/view3"/>
<ListView
android:layout_width="match_parent"
android:id="#+id/un_paid_list_view"
android:layout_height="wrap_content"
android:layout_below="#+id/ll3"/>

LinearLayout not work with RelativeLayout

I want to create following layout.
--------------------------------
Title
Summary Info
[Get Direction][Call][More Info]
--------------------------------
I code following layout but buttons not showing. I have no idea why LinearLayout works like FrameLayout so the RelativeLayout hides buttons. Did I miss something here?
I am using support library 22.1
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/location_card_height">
<ImageView android:id="#+id/cardImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<TextView android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:singleLine="true"
android:hint="Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/title">
<TextView android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Info"
android:layout_alignParentRight="true"
android:ellipsize="end" />
<TextView android:id="#+id/summary"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Summary"
android:layout_toLeftOf="#id/info"
android:ellipsize="end" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnDirection"
android:text="#string/get_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnCall"
android:text="#string/label_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnMoreInfo"
android:text="#string/more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
Your relative layout has been set to match_parent for it height!
change it to wrap_content
that should help you
or put it in a LinearLayout
something like this :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/location_card_height">
<ImageView android:id="#+id/cardImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="vertical" >
<RelativeLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<TextView android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:singleLine="true"
android:hint="Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/title">
<TextView android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Info"
android:layout_alignParentRight="true"
android:ellipsize="end" />
<TextView android:id="#+id/summary"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Summary"
android:layout_toLeftOf="#id/info"
android:ellipsize="end" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="#+id/btnDirection"
android:text="#string/get_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnCall"
android:text="#string/label_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnMoreInfo"
android:text="#string/more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
If you are fine With Linearlayout Then Here is Your XML file
<?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="vertical"
android:weightSum="1" >
<ImageView
android:id="#+id/cardImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/summary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/info"
android:layout_weight="1"
android:ellipsize="end"
android:hint="Summary"
android:singleLine="true"
android:text="Summary"
android:textAppearance="?android:attr/textAppearance" />
<TextView
android:id="#+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="right"
android:hint="Info"
android:singleLine="true"
android:text="Info"
android:textAppearance="?android:attr/textAppearance" />
</TableRow>
</LinearLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnDirection"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get_direction" />
<Button
android:id="#+id/btnCall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="call" />
<Button
android:id="#+id/btnMoreInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="more_info" />
</LinearLayout>

Descendents layouts not appearing

I'm trying to define more than one LinearLayout to fit a form and a button bar at the bottom of my activity but it's not appearing, before my changes all the forms was with ScrollView, but I removed that because I will not use anymore, but when I removed my layout is not appearing anymore, anyone has any solutions what I did wrong ? or forget ?
Here is my new code, but when I turn the orientation to landscape my buttons disappear. how can I fix that ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Cliente: "
android:textSize="18sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<br.com.stara.iris.mobile.tmp.DelayAutoCompleteTextView
android:id="#+id/nota_cliente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="2"
android:imeOptions="flagNoExtractUi|actionSearch"
android:inputType="textCapSentences" />
<ProgressBar
android:id="#+id/nota_cliente_loading_indicator"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="#dimen/margin_default"
android:visibility="gone" />
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Dados do Dispositivo: "
android:textSize="18sp" />
<Spinner
android:id="#+id/dadosdispo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Número de Série: "
android:textSize="18sp" />
<EditText
android:id="#+id/nota_numeroserie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Digite o n° serie"
android:maxLength="18" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Descrição: "
android:textSize="18sp" />
<EditText
android:id="#+id/nota_descricao"
android:layout_width="match_parent"
android:layout_height="120dp"
android:hint="Digite a descrição"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_nota_itenslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Itens" />
<Button
android:id="#+id/btn_nota_ordenslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Ordens" />
<Button
android:id="#+id/btn_nota_limpar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Limpar" />
<Button
android:id="#+id/btn_nota_salvar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Salvar" />
</LinearLayout>
</LinearLayout>
and here its what I want, but when turns the landscape mode my buttons don't disappear, and I could figure out in this way but I don't know if is right or not.
and with the tag android:gravity="center|bottom" I wish to set these bar button in the last line of my activity the last widget bar lets say these way, but I'm not figuring out how?
And also how can I split by equal the size of the buttons to fit the size of the screen ?
only need to change layout_height to 0dp of ScrollView apply a weight 1 not for LinearLayout(which is inside ScrollView) do like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Cliente: "
android:textSize="18sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<br.com.stara.iris.mobile.tmp.DelayAutoCompleteTextView
android:id="#+id/nota_cliente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="2"
android:imeOptions="flagNoExtractUi|actionSearch"
android:inputType="textCapSentences" />
<ProgressBar
android:id="#+id/nota_cliente_loading_indicator"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="#dimen/margin_default"
android:visibility="gone" />
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Dados do Dispositivo: "
android:textSize="18sp" />
<Spinner
android:id="#+id/dadosdispo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Número de Série: "
android:textSize="18sp" />
<EditText
android:id="#+id/nota_numeroserie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Digite o n° serie"
android:maxLength="18" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Descrição: "
android:textSize="18sp" />
<EditText
android:id="#+id/nota_descricao"
android:layout_width="match_parent"
android:layout_height="120dp"
android:hint="Digite a descrição" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_nota_itenslist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Itens" />
<Button
android:id="#+id/btn_nota_ordenslist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Ordens" />
<Button
android:id="#+id/btn_nota_limpar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Limpar" />
<Button
android:id="#+id/btn_nota_salvar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Salvar" />
</LinearLayout>
</LinearLayout>
Try Relative Layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Cliente: "
android:textSize="18sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<br.com.stara.iris.mobile.tmp.DelayAutoCompleteTextView
android:id="#+id/nota_cliente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="2"
android:imeOptions="flagNoExtractUi|actionSearch"
android:inputType="textCapSentences" />
<ProgressBar
android:id="#+id/nota_cliente_loading_indicator"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="#dimen/margin_default"
android:visibility="gone" />
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Dados do Dispositivo: "
android:textSize="18sp" />
<Spinner
android:id="#+id/dadosdispo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Número de Série: "
android:textSize="18sp" />
<EditText
android:id="#+id/nota_numeroserie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Digite o n° serie"
android:maxLength="18" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Descrição: "
android:textSize="18sp" />
<EditText
android:id="#+id/nota_descricao"
android:layout_width="match_parent"
android:layout_height="120dp"
android:hint="Digite a descrição" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center|bottom"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_nota_itenslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Itens" />
<Button
android:id="#+id/btn_nota_ordenslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Ordens" />
<Button
android:id="#+id/btn_nota_limpar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Limpar" />
<Button
android:id="#+id/btn_nota_salvar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#drawable/button_selector"
android:text="Salvar" />
</LinearLayout>
</RelativeLayout>

ScrollView is not scrolling overflowed layout

I have a scroll view containing one child layout(linear layout) and that child contains a relative layout and a linear layout. Relative layout and linear layout shares half-half screen. Linear layout has buttons added to it dynamically.
Now problem arises as scroll view does not scroll buttons while it scrolls relative layout and linear layout.
<ScrollView>
<LinearLayout>
<RelativeLayout>
</RelativeLayout>
<LinearLayout>
->Dynamically adding buttons here
</LinearLayout>
</LinearLayout>
</ScrollView>
I want those buttons scroll with scrollview
For reference my xml code is :-
<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/whitecolor"
android:orientation="vertical"
>
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bluecolor"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stauslinearlayout"
android:layout_marginBottom="8dp"
android:padding="5dp"
android:gravity="center"
android:textColor="#color/whitecolor"
android:text="#string/app_name"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="#color/bluecolor"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/edit_text_custom"
android:singleLine="true"
android:hint="#string/status"
android:textColor="#000"
android:textColorHint="#5222"
android:padding="7dp"
android:maxLength="50"
android:cursorVisible="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:drawableLeft="#android:drawable/ic_input_add"
android:ems="10"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:gravity="center"
android:layout_weight="0"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:padding="5dp"
android:text="#string/statusnumber"
android:background="#drawable/edit_text_custom"
/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/whitecolor"
android:text="abcdfrg"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
AFAIK, If you want to divide screen in to same two sizes, you have to take another scrollView in bottom view, like below example...
<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" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stauslinearlayout"
android:layout_marginBottom="8dp"
android:gravity="center"
android:padding="5dp"
android:text="#string/app_name"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/darker_gray"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:cursorVisible="true"
android:drawableLeft="#android:drawable/ic_input_add"
android:ems="10"
android:hint="status"
android:maxLength="50"
android:padding="7dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#5222" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0"
android:gravity="center"
android:padding="5dp"
android:text="statusnumber" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:text="abcdfrg" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
and if you don't want to take another scrollView, then you have to give wrap_contant to bottom linear-layout.
<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" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stauslinearlayout"
android:layout_marginBottom="8dp"
android:gravity="center"
android:padding="5dp"
android:text="#string/app_name"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/darker_gray"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:cursorVisible="true"
android:drawableLeft="#android:drawable/ic_input_add"
android:ems="10"
android:hint="status"
android:maxLength="50"
android:padding="7dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#5222" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0"
android:gravity="center"
android:padding="5dp"
android:text="statusnumber" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:text="abcdfrg" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
choice goes to your requirement.
if any problem yet, then plz ask... :-)

Categories

Resources