I'm trying to put the view pager inside a table row and I set the view pager layout height match parent. the result is that the view pager has no height at all. I have to set the layout height in dp so that the view pager can have a height. But what I'm inflating inside the view pager is dynamic, therefore I can't set the height inside the xml. The scrollview already fill the screen, but the viewpager doesn't have any height at all. Is there any way to get around this? (the view pager that has a problem is the one that has id pager_problem)
EDIT :
okay, now after I change it, the viewpager exists, but only as big as the screen, I want to make the content inside the viewpager scrollable if the fragment content is long (all the layout scrollable, not only the fragment in view pager)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableRow>
<android.support.v4.view.ViewPager
android:id="#+id/pager_image"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
</TableRow>
<TableRow android:tag="sticky">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:id="#+id/tab"
android:tag="sticky"
android:layout_below="#id/pager_image"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/frame_general_tab"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="GENERAL"/>
</LinearLayout>
<LinearLayout
android:id="#+id/frame_detail_tab"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#color/gray_F2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="DETAIL"/>
</LinearLayout>
<LinearLayout
android:id="#+id/frame_foto_tab"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#color/gray_F2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="FOTO"/>
</LinearLayout>
</LinearLayout>
</TableRow>
<TableRow>
<!--<LinearLayout android:id="#+id/page_container"
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginBottom="70dp"
android:layout_height="match_parent">
</LinearLayout>-->
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginBottom="70dp"
android:layout_height="match_parent"/>
</TableRow>
</TableLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:columnCount="2"
android:background="#color/gray_F2"
android:rowCount="3"
android:orientation="vertical"
android:layout_height="70dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:textSize="15dp"
android:layout_gravity="right"
android:textColor="#color/gray_72"
android:text="Harga mulai"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textSize="20dp"
android:layout_gravity="right"
android:text="Rp 10.560.000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:textSize="15dp"
android:layout_gravity="right"
android:textColor="#color/gray_72"
android:text="per kamar per malam"/>
<Button android:layout_width="150dp"
android:layout_marginLeft="20dp"
android:layout_height="match_parent"
android:layout_rowSpan="3"
android:background="#color/traveloka_button_orange"
android:textColor="#color/white"
android:layout_margin="10dp"
android:text="LIHAT KAMAR"/>
</GridLayout>
</RelativeLayout>
</RelativeLayout>
You need to set android:fillViewport="true" to the scrollview
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
Related
is the view which I have designed with the following code of xml
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
....
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="84dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_above="#+id/meal_ln"
android:background="#drawable/meal_img_bg_ac"
app:layout_aspectRatio="100%"
/>
<TextView
android:id="#+id/meal_ln"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lunch"
android:textAlignment="center"
android:textColor="#color/priTxtLight"
android:layout_alignParentBottom="true"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:fontFamily="casual"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
....
</RelativeLayout>
</LinearLayout>
My target is to design . And for this I added
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleX="1.6"
android:scaleY="1.6"
>
in the second one which result in view cut as
How can I correct this issue?
I want to scale the middle view bigger than other two. In this both the image and text should be visible and should be bigger.
Problem which I found is: Linear layout is hiding the content of overflowing relative layout.
Try using LinearLayout with orientation vertical instead of RelativeLayout
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
....
</RelativeLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView
android:layout_width="84dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_above="#+id/meal_ln"
android:background="#drawable/meal_img_bg_ac"
app:layout_aspectRatio="100%"
/>
<TextView
android:id="#+id/meal_ln"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lunch"
android:textAlignment="center"
android:textColor="#color/priTxtLight"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:fontFamily="casual"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
....
</LinearLayout>
</LinearLayout>
I have one parent LinearLayout and inside it I have two child LinearLayout. I have 4 TextView in 1st child layout and 2 TextView in 2nd child layout. Parent layout has property android:layout_height="wrap_content as well as child layout too.
I want to set height of 1st child layout to 2nd child layout because 1st child layout has 4 textbox and 2nd child layout has to textbox.
I just want to adjust the height of 2nd child layout. I am putting my code below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8"
android:orientation="vertical">
<TextView
android:id="#+id/lblBooking_Code"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/lblSession"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/lblCustomer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/lblAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/lblMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:orientation="vertical">
<TextView
android:id="#+id/lblBooking_Gross_Amt"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/lblBooking_PayAmt"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/lblBooking_Balance"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Make the height of 2nd child layout "match_parent"
Making the height of 2nd child layout "match_parent" and implementing "weightSum=3" I achieved my requirement.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8"
android:orientation="vertical">
<TextView
android:id="#+id/lblBooking_Code"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/lblSession"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/lblCustomer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/lblAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/lblMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".1"
android:weightSum="3"
android:orientation="vertical">
<TextView
android:id="#+id/lblBooking_Gross_Amt"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/lblBooking_PayAmt"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:id="#+id/lblBooking_Balance"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
You can see the code below that belongs layout design.
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/profilePic2"
android:layout_width="#dimen/feed_item_profile_pic"
android:layout_height="#dimen/feed_item_profile_pic"
android:scaleType="fitCenter" >
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/feed_item_profile_info_padd" >
<TextView
android:id="#+id/name2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/feed_item_profile_name"
android:textStyle="bold" />
<TextView
android:id="#+id/timestamp2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/timestamp"
android:textSize="#dimen/feed_item_timestamp" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textCategory2"
android:layout_weight="1"
android:textStyle="normal|bold"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/content2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="#dimen/feed_item_status_pad_left_right"
android:paddingRight="#dimen/feed_item_status_pad_left_right"
android:paddingTop="#dimen/feed_item_status_pad_top"
android:layout_weight="1"/>
<ImageView
android:id="#+id/contentImage2"
android:layout_width="match_parent"
android:background="#color/white"
android:scaleType="fitCenter"
android:visibility="visible"
android:cropToPadding="false"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:srcCompat="#drawable/bg_parent_rounded_corner"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:isScrollContainer="false"
android:keepScreenOn="false"
android:measureWithLargestChild="false"
android:verticalScrollbarPosition="defaultPosition"
android:paddingBottom="10dp">
<TextView
android:text="#string/yorumlar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_weight="1"/>
<ListView
android:layout_width="match_parent"
android:id="#+id/comList"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:clipChildren="false"
android:headerDividersEnabled="false"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
We can see details of the post showing up top of the screen, comments are at the bottom of the screen. Comments doesnt show up entirely despite of scrollview included listview and i have “layout_height:wrap_content”. First comment showing up but else doesnt show up with scroll.
Thanks for the answers
Screenshot
You have to change following things to display the list:
change the height of root linear layout from wrap content to match parent.
android:layout_height="match_parent"
do the same thing to scroll view
android:layout_height="match_parent"
3 now change the height of listview, I have given android:layout_height="500dp" this. You can adjust this with your requirement.
NOTE: List view will not work inside scrollview without giving static height. So you have to give height as 400..500dp or you can remove scrollview.
I am using a webview to load html data.
I want to place two buttons on the bottom for some functionality.
I have put teh webview and the bottom layout in a frame layout.
Web view shows html data only when i give it some specific height e.g 500dp.
Also the bottom layout also scrolls along with webview.
Please help how i can do this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/newsHeading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="Heading"
android:textColor="#000000"
android:textSize="18sp" />
<WebView
android:id="#+id/webviewNews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/black"
android:padding="10dp" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back1"
android:padding="20dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/share11"
android:padding="20dp" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
I had the same problem and I have fixed it by changing the LinearLayout by a RelativeLayout and setting all the "parent aligments" to the WebView, but this fill the screen.
For your layout, try align your button's LinearLayout to the parent's bottom, and replace the alignParentBottom of the WebView by a layout_above anchored to it. I have tested it and works fine.
Here is the code, try it:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="#+id/linlyt_buttons"/>
<LinearLayout
android:id="#+id/linlyt_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/rellyt_imagebuttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#color/black"
android:padding="10dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/ic_menu_close_clear_cancel"
android:padding="20dp"
android:contentDescription="Back/Cancel"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#android:drawable/ic_menu_share"
android:padding="20dp"
android:contentDescription="Share"/>
</RelativeLayout>
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
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:layout_marginTop="5dp">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2"/>
</LinearLayout>
</LinearLayout>
I've a framelayout with a listview and a linearlayout (bottom bar) at the bottom of this.
When expand the listview, I can't scroll properly because the linearlayout at the bottom has covered the child of listview.
I don't understand where is the problem...I would like separate the bottom bar from the listview.
This is my layout (possibly, can you optimize this layout?):
<FrameLayout 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.robertot.timereport.com.robertot.timereport.pages.WeeklyStatFragment">
<RelativeLayout
android:id="#+id/rlList"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listWeek"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
style="#android:style/Widget.Holo.Light.ActionBar.Solid">
<Spinner
android:id="#+id/spnYearW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"/>
<Spinner
android:id="#+id/spnMonthW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
<ImageButton
android:id="#+id/btnFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_search"
android:background="#null"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</FrameLayout>
thanks!!
The problem is your FrameLayout doesn't prevent your Views from overlapping, which is why your ListView appears below it. One solution, that wouldn't require you to change much, would be to put your bottom LinearLayout inside your RelativeLayout and use the alignParentBottom and layout_above attributes to position things:
<FrameLayout 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.robertot.timereport.com.robertot.timereport.pages.WeeklyStatFragment">
<RelativeLayout
android:id="#+id/rlList"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listWeek"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/bottom_linear" />
<LinearLayout
android:id="#+id/bottom_linear"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
style="#android:style/Widget.Holo.Light.ActionBar.Solid">
<Spinner
android:id="#+id/spnYearW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"/>
<Spinner
android:id="#+id/spnMonthW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
<ImageButton
android:id="#+id/btnFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_search"
android:background="#null"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>
</FrameLayout>