Android nested layout with layout_weight - android-layout

I would like to create left and right reserved spaces (LinearLayout) on screen which give me felexiblitiy to ensure my UI is working in different size of screen as I want,
and in middle create a TableLayout to apply views and contorls, everything good great
except TableRow - android:layout_width is became zero, TableLayout width is not really zero however I had to put android:layout_width="0dp" for TableLayout to force android:layout_weight="4" working
how can I tell TableRow to take actual parnt(TableLayout) width
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/widget33"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
<TableLayout
android:id="#+id/widget34"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="4">
<TableRow
android:id="#+id/widget64"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/widget72"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I m here" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="#+id/widget35"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>

Related

BottomSheet move to top of screen when changing visibility of its component

I have a bottom sheet with a NestedScrollView inside (see below). When I press on a FAB button, I want to make some parts in this NestedScrollView invisible. But when I change some linearlayouts visibilities to GONE, bottomsheet fly aways from the top.
My XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/messageOptionBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/back_miscellaneous"
android:gravity="center"
android:orientation="vertical"
app:behavior_peekHeight="0dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/textSecondary" />
<LinearLayout
android:id="#+id/layoutDeleteMessage"
android:layout_width="match_parent"
android:layout_height="#dimen/_35sdp"
android:layout_margin="#dimen/_10sdp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:animateLayoutChanges="true"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="#dimen/_22sdp"
android:layout_height="#dimen/_22sdp"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_remove" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_10sdp"
android:fontFamily="#font/ubuntu_medium"
android:includeFontPadding="false"
android:text="#string/delete_message"
android:textColor="#color/textSecondary"
android:textSize="#dimen/_12ssp" />
<TextView
android:id="#+id/textConfirmDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_10sdp"
android:fontFamily="#font/ubuntu_medium"
android:gravity="end"
android:includeFontPadding="false"
android:text="#string/confirm"
android:textColor="#color/red"
android:textSize="#dimen/_12ssp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
Your bottom sheet is moving top because you are using
android:animateLayoutChanges="true"
remove this line from your layoutDeleteMessage (Linear layout)
Hope this solve your problem

Overlap the layout in the android ExpandableListView

In the following template , at the above New vhd text,
overlap the row , I want to fix this problem .I tried to change the height of the Main File but no used.I just increase the text Size 14 to 15 PX in the all template ,size increased in main template programmatically, this problem occur. I attached my code with the question also see the commented section in XML file.Please suggest me solution if any.I am new to android .Not familiar with the android.I also attached the image below.Thank you.
//Main file
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" //Changed the height but not work
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="vertical"
android:background="#color/green">
<TextView
android:id="#+id/queue_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/white"
android:text="Inbox"
android:textStyle="bold"
android:gravity="center_vertical"
android:layout_marginLeft="10dp" />
</LinearLayout>
<ExpandableListView android:id="#+id/que_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" //changed as fill_parent but not worked
android:groupIndicator="#drawable/settings_selector"/>
</LinearLayout>
//Second File
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> //changed as fill_parent but not worked
<TextView android:id="#+id/groupname"
android:paddingLeft="50px"
android:paddingTop="10px"//changed as 15px not worked
android:paddingBottom="10px"//changed as 15px not worked
android:textSize="15px"
android:textColor="#0b730b"
android:layout_width="250px"
android:layout_height="wrap_content"/>//changed as fill_parent but not worked
</LinearLayout>
//Third file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">//changed as fill_parent but not worked
<ImageView
android:id="#+id/imageView1"
android:paddingLeft="40px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/green" />
<TextView android:id="#+id/childname"
android:paddingLeft="20px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="15px"
android:textColor="#0b730b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/child_id"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/dept_id"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/rgb"
android:textSize="16px"
android:layout_marginLeft="10px"
android:textColor="#0b730b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Android Linear layout and percentage

I want to create layout similar to one attached. The left hand side needs to be scrolled text occupying 75% of screen horizontally. The remaining 25% will consists of few icons stacked vertically and a button that should align at the bottom.
But I can't seem to get the working.
http://i.imgur.com/TzzBy9h.png
I would appreicate any help in getting this layout stuff right, my current layout looks like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/card_details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="50"
android:layout_weight="0.7"
android:gravity="bottom"
android:text="" >
</TextView>
<ImageView
android:id="#+id/photo_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:minHeight="84dp"
android:minWidth="84dp"
android:scaleType="centerCrop" />
</LinearLayout>
</ScrollView>
<LinearLayout android:gravity="center" android:orientation="horizontal"
android:padding="4.0dip" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/read_id_btn"
style="#style/PageButton"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="#string/read_id" />
</LinearLayout>
</LinearLayout>
~
Try weigth "2" and "1".
Good luck with it.
Try This code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="15dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>

How to display a SeekBar correctly? (layout_weight)

I`m trying to create the following 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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
I`d like to give the 80% of the parent layout to the textView1 and textView2, wrap the SeekBar as much as possible and the rest of the free space give to the textView3.
I`ve tried to:
use layout_weight attributes (respectively - 4, 4, 1, 1) but the last
view overlaps the SeekBar
use layout-weight only with textView1 and textView2, set SeekBar`s height to "wrap_content" and set "match_parent" for the last view
And now I have no more ideas. Have you ever had such a problem?
well to create this layout I would try :
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
</TextView>
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
</TextView>
make change on weights tu adjust sizes.
let the seek bar to wrap content, give weight on other views.
tell me if that helps.

how to put scrolled textview on secroll layout

i have to use scrolled textview on scrolled layout so if i want to scroll the textview the whole layout scrolled when need just scrolled the textview and when scroll out text-view the whole layout scrolled see the code t
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollViewOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="460dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="54dp"
android:orientation="vertical" >
</LinearLayout>
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="247dp"
android:layout_height="240dp"
android:layout_gravity="center_horizontal"
android:scaleType="center"
android:src="#drawable/image1" />
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
<TextView
android:id="#+id/lblTextViewBig"
android:layout_width="229dp"
android:layout_height="91dp"
android:layout_gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:maxLines="3"
android:scrollbarTrackVertical="#id/lblTextViewBig"
android:scrollbars="vertical"
android:singleLine="false"
android:text="#string/namm" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
A couple of items:
1) You have a dangling '>' near the end of your code.
2) If you want to just scroll the TextView, then only wrap the textview in the scrollview, see Scroll view for textview in android for an example.

Resources