add view to vertical linearlayout inside horizontallscrollview within scrollview - android

I want to programatically add viwes to vertical orientation linearlayout within horizontalscrollview within Scrollview. Basic scheme of my layout is belowe:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdge="none">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- same header code -->
</LinearLaout>
<HorizontalScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<LinearLayout
android:id="#+id/list_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"/>
</HorizontalScrollView>
</ScrollView>
Now if i'm adding programatically 5 views to list_view linearlayout, i get only one view, and free sapce below it. If i comment HorizontallScrollView like that:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdge="none">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- same header code -->
</LinearLaout>
<LinearLayout
android:id="#+id/list_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"/>
</ScrollView>
All views are show correct, but they aren't horizontall scrollable. Please give me same ideas how to solve this problem.

Answer is to change linearlayout's android:layout_width attribute to wrap_content within horizontalScrollview

Related

How to remove extra space from the bottom of Scrollview

How to remove extra space from the bottom of Scrollview. Below is the XML layout where I am including two external layouts. Have refered many solutions but none of them worked for me.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sc"
android:layout_marginBottom="55dp"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideOverlay"
android:layout_weight="1"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/linprodetaill"
android:layout_above="#+id/bt"
android:layout_height="wrap_content">
<include
android:id="#+id/l1"
layout="#layout/productexpand_items" />
<include
android:id="#+id/l3"
layout="#layout/dynamic_view"
/>
</LinearLayout>
</ScrollView>
Remove android:layout_marginBottom="55dp" from your ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sc"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideOverlay"
android:layout_weight="1"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/linprodetaill"
android:layout_above="#+id/bt"
android:layout_height="wrap_content">
<include
android:id="#+id/l1"
layout="#layout/productexpand_items" />
<include
android:id="#+id/l3"
layout="#layout/dynamic_view"
/>
</LinearLayout>
</ScrollView>
Remove this line from your xml
android:layout_marginBottom="55dp"
it will remove the extra space , u can set 10dp just to give enough spacing
nest your scrollView and the other layouts in a Relative layout.
and then use the layout_below attribute to align the layouts below your scrollView.
and make sure to inclue layout_alignParentTop="true" in your scrollView's xml and remove the bottom margin of your scrollView.
now when the bottom layouts have their visibility value changed to Visible or Gone, scrollView will fill the parent or leave room for them,

Dynamically adding RecyclerViews to a LinearLayout does not increase the height

I am trying to add many RecyclerViews dynamically to a LinearLayout depending upon the x coordinate of a 2-D array (Set). All the children of each view are not visible (it appears on scrolling the view).
In short, making the RecyclerView's height to WRAP_CONTENT is not stretching the height of RecyclerView.
I want all the children of all the RecyclerViews to be visible and not let any RecyclerView to be scrollable.
Following is the table_layout which I add dynamically:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Engine"
android:padding="6dp"
android:gravity="center"
android:id="#+id/tv_label"
android:layout_marginTop="16dp"
android:background="#color/light_gray"
android:textSize="#dimen/bid_report_label_text_size"
android:textColor="#color/white"
android:textStyle="bold"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view"/>
</LinearLayout>
Following is the activity_main layout of activity:
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_bid_now"
android:id="#+id/scrollView">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linear_layout_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="210dp"
android:id="#+id/bike_image"
android:onClick="startImageSlideshow"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linear_layout_details"
android:orientation="vertical"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I add table_layout to activity_main dynamically.
Please tell me how to make the RecyclerView WRAP_CONTENT?
The problem was with ScrollView. Changing it to NestedScrollView solved the problem.

android make view to wrap content but not larger than a specific size

I have a Relative View which has two children an scroll view and a button below it now i want to do this: i want this view to wrap it's content and does not make empty space and also not to exceed screen size.
how can i do that? can any one help?
here is my current layout file which is not working.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
</ScrollView>
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/content"
... />
</RelativeLayout>
RelativeLayout does not have such possibility. However LinearLayout does. Just set LinearLayout's android:orientation to vertical, set ScrollView's android:layout_weight to 1, and it should be working:
<?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">
<ScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ScrollView>
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
You should use LinearLayout and adjust both the views according to a weight.In that way it will not exceed in any resolution and will adjust acording to the size of screen.
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ScrollView
android:fillViewPort="true"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
</ScrollView>
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="#id/content"
... />
</LinearLayout>
You should make action button align at the bottom and that scroll view should be above that button. In this way scroll view will always be in screen and also button will be visible.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
... />
<ScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_above="#id/action"
android:layout_height="match_parent">
....
</ScrollView>
</RelativeLayout>

Place LinearLayout below FrameLayout with ListView

I want to place a LinearLayout below a FrameLayout which contains a ListView, but the content of the LinearLayout is not shown.
I also tried this out with a surrounding LinearLayout instead of the RelativeLayout without success.
The FrameLayout cannot be changed to different layout type!
The LinearLayout below will be shown and hidden programmatically.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/framelayout_container" >
<ListView
android:id="#+id/content_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#FFFFFF"
android:dividerHeight="1dp"
android:padding="0dp" >
</ListView>
<LinearLayout
android:id="#+id/description_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" >
<include
android:id="#+id/description_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/included_layout" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/below_container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_alignParentBottom="true"
android:background="#33b5e5" >
<include
android:id="#+id/below_layout"
layout="#layout/below_layout"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
Any ideas how to get this work?
The problem is your FrameLayout is set to match the parent width and height, so it will leave no room for the LinearLayout beneath it. You would need to revise it to use its layout_height set to wrap_content, and change the inner ListView to do the same.

How to scroll a view which is not in scrollview?

I designed a headerlayout(background is transparent) which is not in the scrollview and a scrollview which is in below of that header,in that scrollview have a layout with fixed height 1000dp and in the scrollview i added the views dynamically upto this its fine for me..But my problem is when i scroll the scrollview the background image also moving(background image height is 1550px) at the same time i want to change the background for the header as it is in scrollview background.....
i am not able to implement this please anyone help me in this designing..Below is my designing code..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/navbar"
android:background="#drawable/navbar_blooptransprant64"
/>
<ScrollView
android:layout_below="#+id/navbar"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1000dp"
android:background="#drawable/new_bg"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/outer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>

Categories

Resources