Nested LinearLayout does not align to parent ScrollView? - android-layout

I have a fragment with two horizontal Buttons (yellow = fragment_test_button_container) at the bottom of my fragment. I would like to use the remaining area (red = fragment_test_scrollview) for a ScrollView It is reuiqred that my ScrollView consist of one layout (turquoise = fragment_test_check) only . This can then in turn have further layouts, as you can see in the attached fragment_test.xml
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.TestFragment">
<ScrollView
android:id="#+id/fragment_test_scrollview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/fragment_test_button_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent=".84"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/fragment_test_check"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/fragment_test_front_photo_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".28"
android:orientation="horizontal">
<TextView
android:id="#+id/fragment_test_front_photo_title"
style="#style/myapp_MediumTextStyle"
android:layout_width="#dimen/myapp_test_fragment_textview_width"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="24dp"
android:text="#string/fragment_test_front_photo_title_text" />
<ImageView
android:id="#+id/fragment_test_front_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/fragment_test_back_photo_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".28"
android:orientation="horizontal">
<TextView
android:id="#+id/fragment_test_back_photo_title"
style="#style/myapp_MediumTextStyle"
android:layout_width="#dimen/myapp_test_fragment_textview_width"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="24dp"
android:text="#string/fragment_test_back_photo_title_text" />
<ImageView
android:id="#+id/fragment_test_back_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<!-- ADDITIONAL DATA -->
<LinearLayout
android:id="#+id/fragment_test_data_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".34"
android:orientation="vertical"
android:paddingStart="24dp"
android:paddingEnd="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/fragment_test_value1_label"
style="#style/myapp_MediumTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text=„Value1^“ />
<TextView
android:id="#+id/fragment_test_value1_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/fragment_test_value2_label"
style="#style/myapp_MediumTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text=„Value2“ />
<TextView
android:id="#+id/fragment_test_value2_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/fragment_test_value3_label"
style="#style/myapp_MediumTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Ausstellungsdatum" />
<TextView
android:id="#+id/fragment_test_value3_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="24dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/fragment_test_button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="24dp"
android:paddingEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/fragment_test_scrollview">
<Button
android:id="#+id/fragment_test_back_button"
style="#style/myapp_ContinueBackButtonStyle"
android:layout_width="0dp"
android:layout_height="#dimen/myapp_continueBackButton_height"
android:layout_weight="1"
android:background="#color/myapp_colorPrimary"
android:text=„back“
android:textColor="#FFFFFF" />
<Button
android:id="#+id/fragment_test_next_button"
style="#style/myapp_ContinueBackButtonStyle"
android:layout_width="0dp"
android:layout_height="#dimen/myapp_continueBackButton_height"
android:layout_marginStart="24dpVerySmall"
android:layout_weight="1"
android:background="#color/myapp_colorPrimary"
android:text="continue"
android:textColor="#FFFFFF" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
But my turqoise (fragment_test_check) area is not aligned fully with the blue area (fragment_test_scrollview), altough I wrote match_parent. I would like the heigth of turqoise area as the blue area.
Why is my turqoise area dangling in half the blue area?

Set android:fillViewport="true" in your ScrollView.
fillViewport stretches the content's height to the viewport's boundaries, when set true. In simple words, fillViewport decides whether the nested contents of the layout should match the parent's boundaries or not. Thus, to make the nested layout match the parent's boundary, set fillViewport to true
Moreover, the layout_gravity for nested components should be 1 or whatsoever you define in weight_sum of parent layout, whereas in your case it is 0.90 .

Related

Android listview with Color Border in vertical

I have been struggling for a while to draw vertical border.I want to use a ListView to make a report wheres the results is divided into squares and mixed up.Tried with multiple codes but could not, If any one can suggest the mistakes in my codings would be great.
Horizontal is working fine whereas vertical could not it.
Even with vertical in color do fine.
Current Listview Appears as follows :
Expected Listview format as follows: Vertical and Horizontal Border or Grid needed in between the contents.
Layout:
**
<?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:background="#FFC7C7C7"
android:orientation="vertical"
android:divider="#drawable/mydivider"
android:showDividers="middle"
android:dividerPadding="22dp"
android:weightSum="9">
<LinearLayout
android:id="#+id/lvcontainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="0.5"
android:background="#FFC7C7C7"
android:orientation="horizontal"
android:padding="1dp"
android:weightSum="3">
<TextView
android:id="#+id/txtproductcompany"
style="?android:dividerVertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.63"
android:gravity="left"
android:text="no"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductname"
style="?android:dividerVertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.59"
android:gravity="left"
android:padding="3dp"
android:text="number"
android:textColor="#000000"
android:textSize="9sp" />
<TextView
android:id="#+id/txtproductprice"
style="?android:dividerVertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="name"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice1"
style="?android:dividerVertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="sun"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="mon"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="tuesday"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice4"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="wednesday"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice5"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="thursday"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice6"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="saturday"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice7"
android:layout_width="33dp"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="closed"
android:textColor="#000000"
android:textSize="13sp" />
<TextView
android:id="#+id/txtproductprice8"
android:layout_width="21dp"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="calling"
android:textColor="#000000"
android:textSize="13sp"
android:layout_weight="0.60" />
<TextView
android:id="#+id/txtproductprice9"
android:layout_width="21dp"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dp"
android:text="week"
android:textColor="#000000"
android:textSize="13sp"
android:layout_weight="6.22" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_height="0dp"
android:layout_below="#+id/lvcontainer"
android:layout_weight="8.72"
android:layout_width="match_parent"
android:divider="#drawable/separator_line"
android:dividerHeight="4.0sp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:dividerPadding="10dp"
android:layout_centerVertical="true"
android:showDividers="beginning|middle|end"
android:cacheColorHint="#00000000"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
></ListView>
<TextView
android:id="#+id/txtresulttext"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#android:id/list"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_weight="0.5"
android:gravity="left"
android:text=""
android:textColor="#FFF55F54"
android:textSize="20sp"
android:textStyle="italic|bold"></TextView>
<LinearLayout
android:id="#+id/lvbottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/btnupload"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#1083f5"
android:gravity="center"
android:text="UPLOAD"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold"
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>
**
Mycontroller:
myList = controller.getAllProducts();
if (myList.size() != 0) {
ListView lv = getListView();
ListAdapter adapter = new SimpleAdapter(import2.this, myList,
R.layout.display2, new String[]{ "id","number", "outletname","sunday", "tuesday" , "wednesday" ,"thursday", "saturday" , "monday","calling","closed"}, new int[]{
R.id.txtproductcompany,R.id.txtproductname,R.id.txtproductprice,R.id.txtproductprice1,R.id.txtproductprice2,R.id.txtproductprice3,R.id.txtproductprice4,R.id.txtproductprice5,R.id.txtproductprice6,R.id.txtproductprice7,R.id.txtproductprice8});
setListAdapter(adapter);
lbl.setText("");
}
code resutls.
Bar in the bottom,
same like this .
Since you want to show a table made of ListView rows, you have to make sure that columns will require the same space in each row.
Or you take an alternative approach and use TableLayout. It will be the better choice if you have a fixed number of rows.
But let's assume you have a varying number of rows. Then your layout for the rows will have to consist of rather rigid cells, so android:width="wrap_content" is not an option for most of the Views.
One way to cope with this is using a set of dimension values for the columns:
dimens.xml
<resources>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="column_id_width">32dp</dimen>
<dimen name="column_number_width">60dp</dimen>
<dimen name="column_outletname_width">60dp</dimen>
<dimen name="column_weekday_width">60dp</dimen>
<dimen name="column_closed_width">48dp</dimen>
<dimen name="column_calling_width">48dp</dimen>
<dimen name="column_week_width">48dp</dimen>
<dimen name="column_wednesday_width">76dp</dimen>
</resources>
... as well as a style for the individual TextViews
<style name="ListItemStyle" parent="TextAppearance.AppCompat.Body1">
<item name="android:textSize">12sp</item>
<item name="android:textColor">#000000</item>
<item name="android:padding">4dp</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:background">#drawable/list_item_background</item>
</style>
with a shape drawable as list_item_background:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent"/>
<stroke android:color="#000000" android:width="1dp"/>
</shape>
The list header:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:background="#aaaaaa"
android:foreground="#drawable/list_header_foreground"
android:layout_margin="2dp"
android:weightSum="1">
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductcompany"
android:layout_width="#dimen/column_id_width"
android:layout_height="wrap_content"
android:text="id3"
android:background="#ffffff"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductname"
android:layout_width="#dimen/column_number_width"
android:layout_height="wrap_content"
android:text="number"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="outletname"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice1"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="wrap_content"
android:text="sunday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice2"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="wrap_content"
android:text="monday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice3"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="wrap_content"
android:text="tuesday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice4"
android:layout_width="#dimen/column_wednesday_width"
android:layout_height="wrap_content"
android:text="wednesday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice5"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="wrap_content"
android:text="thursday"/>
<!-- friday is missing on purpose? -->
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice6"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="wrap_content"
android:text="saturday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice7"
android:layout_width="#dimen/column_closed_width"
android:layout_height="wrap_content"
android:text="closed"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice8"
android:layout_width="#dimen/column_calling_width"
android:layout_height="wrap_content"
android:text="calling"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice9"
android:layout_width="#dimen/column_week_width"
android:layout_height="wrap_content"
android:text="WEEK1"/>
</LinearLayout>
and, last not least, the list row
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_margin="1dp"
android:weightSum="1">
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductcompany"
android:layout_width="#dimen/column_id_width"
android:layout_height="match_parent"
android:text="13" />
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductname"
android:layout_width="#dimen/column_number_width"
android:layout_height="match_parent"
android:text="9003562"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="1rmarket"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice1"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="match_parent"
android:text="Sunday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice2"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="match_parent"
android:text="Monday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice3"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="match_parent"
android:text="Tuesday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice4"
android:layout_width="#dimen/column_wednesday_width"
android:layout_height="match_parent"
android:text="Wednesday"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice5"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="match_parent"
android:text="Thursday"/>
<!-- friday is missing on purpose? -->
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice6"
android:layout_width="#dimen/column_weekday_width"
android:layout_height="match_parent"
android:text="No"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice7"
android:layout_width="#dimen/column_closed_width"
android:layout_height="match_parent"
android:text="Yes"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice8"
android:layout_width="#dimen/column_calling_width"
android:layout_height="match_parent"
android:lines="2"
android:text="0001\nDaily"/>
<TextView
style="#style/ListItemStyle"
android:id="#+id/txtproductprice9"
android:layout_width="#dimen/column_week_width"
android:layout_height="match_parent"
android:text="WEEK1"/>
</LinearLayout>
Note: you can use an attribute android:foreground with the LinearLayout in the list header if you want that green frame overlaying the child Views. Another shape drawable similar to list_item_background will do the trick.
Please note also that since I don't know your exact requirements, I left some of the attributes related to dividers alone. You may want to get rid of them if the approach based on shape drawables solves your issue.
The picture shows the Android Studio preview of the list header above a ListView placeholder
I changed the Activity layout to use less layout weights, and everything is set to android:visibility="visible" to make sure it all fits on the screen:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#FFC7C7C7"
android:divider="#drawable/mydivider"
android:dividerPadding="2dp"
android:orientation="vertical"
android:showDividers="middle"
android:weightSum="1">
<include
android:id="#+id/lvcontainer"
layout="#layout/list_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFC7C7C7" />
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:divider="#drawable/separator_line"
android:dividerHeight="4.0sp"
android:dividerPadding="10dp"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:orientation="vertical"
android:showDividers="beginning|middle|end" />
<TextView
android:id="#+id/txtresulttext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:gravity="left"
android:text=""
tools:text="result"
android:textColor="#FFF55F54"
android:textSize="20sp"
android:textStyle="italic|bold" />
<LinearLayout
android:id="#+id/lvbottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/btnupload"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#1083f5"
android:gravity="center"
android:text="UPLOAD"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
As suggested by user 0X0nosugar created three layout. 1.main layout 2. listheader 3.listrow and applied rest matrix as suggested. now working fine
Use Views as borders in your adapter item layout. Use a recycler view instead.

ScrollView overlapping other content in RelativeLayout

I have a drawer menu defined for my app that uses a RelativeLayout as its root.
The general structure of the menu is as follows:
<RelativeLayout
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:clickable="true"
android:focusable="true"
android:importantForAccessibility="no"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear_vert_drwr_hdr"
android:layout_width="match_parent"
android:layout_height="150dp"
android:padding="8dp"
android:background="#drawable/drawer_bg"
android:orientation="vertical">
<ImageView
... />
<TextView
... />
</LinearLayout>
<LinearLayout
android:id="#+id/manage_ids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_vert_drwr_hdr"
android:padding="8dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
... />
<ImageView
... />
</LinearLayout>
<LinearLayout
android:id="#+id/prefs_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/manage_ids"
android:padding="8dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
... />
</LinearLayout>
<ScrollView
android:id="#+id/vscroll_prefs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/prefs_section"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp">
<LinearLayout
android:id="#+id/linear3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical"
android:layout_gravity="start">
<Switch
android:id="#+id/switch_rem_last_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
... />
... a bunch of switches ...
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/i_div_line_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:contentDescription="#string/dividing_line"
android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp"
app:srcCompat="#drawable/line_box" />
<TextView
... />
<TextView
... />
<ImageView
... />
<LinearLayout
android:id="#+id/social_links"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
... />
<ImageView
... />
</LinearLayout>
<TextView
android:id="#+id/l_app_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="8dp"
android:text="#string/app_version"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="italic" />
</LinearLayout>
</RelativeLayout>
This works fine on phones with large screens, but on smaller screens the ScrollView overlaps the LinearLayout below it.
As I'm using a RelativeLayout as the root of the layout I can't use android:layout_height="0dp" and android:layout_weight="1" instead of android:layout_height="wrap_content".
Is there another way to make the ScrollView expand to fill the available space but no more?
Got it.
I gave the LinearLayout below the ScrollView and id, then in the ScrollView I defined android:layout_above="#id/layout_below_the_scrollview".
Simple when you realise just how many android:layout... options there are!

How to add more content in layout? is it possible to define more than 1 textview inside scrollView?

This my code in this I have been using scrollView and inside it two textViews to add more content but it is working only when there is one textView please what changes i do to add more content?And here I want space between those textViews(content) but in my code i am trying for that but the content is overlapped and there is no proper space between contents.please help me..!
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hp.kludge.AndroidActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:weightSum="1">
<TextView
android:id="#+id/tvA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="ANDROID"
android:textColor="#f6080101"
android:textColorHighlight="#df1425"
android:textSize="35dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:background="#e62027"
android:layout_height="2dp"
android:layout_below="#+id/tvC" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:fillViewport="true"
android:orientation="vertical">
<TextView
android:id="#+id/tvWhat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tvC"
android:layout_marginTop="44dp"
android:text="What is Android?"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Content"
android:id="#+id/tvt" />
</ScrollView>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/butNext"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#abc3fb" />
</RelativeLayout>

keyboard overlap custom edittext

Greetings to all. What time I struggle with the problem. By clicking
on the EditText my keyboard covers half EditText. Tried to put in
Manifest adjustSpan - keyboard covers half EditTekst and adjustResize
- displays the top panel also RelativeLayout. Help solve the problem.
main activity layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/color_background_1">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linear_bottom_panel" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5c4768" >
</FrameLayout>
<ListView
android:id="#+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/darker_gray"
android:dividerHeight="0.1dp"/>
<ListView
android:id="#+id/new_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="#android:color/darker_gray"
android:background="#5c4768"
android:dividerHeight="0.1dp"/>
</android.support.v4.widget.DrawerLayout>
<LinearLayout
android:id="#+id/linear_bottom_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#color/color_bottom_panel"
android:orientation="horizontal" >
<ImageView
android:id="#+id/image_main_news"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/ic_main_news_selector" />
<ImageView
android:id="#+id/image_main_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/ic_main_chat_selector" />
<ImageView
android:id="#+id/image_main_add_mp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/ic_main_add_mp_selector" />
<ImageView
android:id="#+id/image_main_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/ic_main_map_selector" />
<ImageView
android:id="#+id/image_main_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/ic_main_user_selector" />
</LinearLayout>
<ProgressBar
android:id="#+id/progress_load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible"
android:indeterminateDrawable="#drawable/load_progress" />
</RelativeLayout>
this fragment 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:background="#color/color_background_1" >
<include
android:id="#+id/discus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="#layout/layout_discus_view"
/>
<ListView
android:id="#+id/list_chat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/discus"
android:layout_above="#+id/add_message"
android:listSelector="#drawable/listview_item_selector"
>
</ListView>
<include
android:id="#+id/add_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="#layout/layout_add_new_message"
/>
</RelativeLayout>
where adjustSpan layout #+id/add_message keyboard overlap

Designing a custom listview row - need advice for positioning elements

So here is the basic layout I'm after: http://i.imgur.com/Y5rHEpc.jpg
In the designer, I can't get the rectangle left-aligned how I want it. Everything just overlaps. http://i.imgur.com/ufWmVgR.png
What would be the best way to lay this out? I'm new and having a really tough time figuring out these layouts. I'm using an extremely simple rectangle shape that I created in my drawables folder.
Any tips appreciated.. I'm really banging my head against the wall here.
<RelativeLayout 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:padding="5dp"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/row_rectimage"
android:layout_width="44dp"
android:layout_height="match_parent"
android:src="#drawable/rectangle" />
<TextView
android:id="#+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/row_title"
android:layout_marginTop="5dp"
android:text="Some Description"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp" />
.....
This adds another nested LinearLayout but the performance loss should be negligible.
<?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="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/row_rectimage"
android:layout_width="44dp"
android:layout_height="match_parent"
android:src="#drawable/rectangle" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView
android:id="#+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/row_title"
android:layout_marginTop="5dp"
android:text="Some Description"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>

Resources