i want to have like this design.header when listview and image bellow in this listview.i wrote xml code.also i used scrollview but my listview's height des not change when i adaptered my array.i can show only first item in listview.
in my option problem is xml file
this is a source xml file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/ic_launcher"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#ff0000" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/geocell" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/relativeLayout1"
android:orientation="vertical" >
<ListView
android:id="#+id/menu_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout2"
android:orientation="horizontal" >
<ImageView
android:id="#+id/popapshow"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/geocell" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Remove LinearLayout from the root and add ScrollView
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
Try this one
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
Related
This question already has answers here:
ListView inside ScrollView is not scrolling on Android
(27 answers)
Closed 6 years ago.
I work on an application that contain an XML file with some ListView I'd like to make them to scroll inside a LinearLayout, so i've done it with ScrollView but it's not possible, i need your helps, thanks in advance, here is my source code :
XML-FILE :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ListViewCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewDimancheCatalogueRDV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/TextViewDimancheCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewDimancheCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewLundiCatalogueRDV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/TextViewLundiCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewLundiCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView>
</LinearLayout>
</LinearLayout>
I would suggest you to use ExpandableHeightListView
If you dont want to use ExpandableHeightListView than you can try following
Never put listview in scroll view. Listview itself is scrollable.
check https://developer.android.com/reference/android/widget/ListView.html
A view that shows items in a vertically scrolling list
you need to use weightSum, check below layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ListViewCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewDimancheCatalogueRDV1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextViewDimancheCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewDimancheCatalogueRDV1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView >
</LinearLayout >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewLundiCatalogueRDV2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextViewLundiCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewLundiCatalogueRDV2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView >
</LinearLayout >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewDimancheCatalogueRDV3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextViewDimancheCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewDimancheCatalogueRDV3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView >
</LinearLayout >
</LinearLayout >
</ScrollView >
In the very first Linear Layout set android:orientation="vertical" android:scrollbars="vertical"
Finally i've found a solution, thanks for all your efforts (^_^), here is a solution : stackoverflow.com/questions/6210895/
I'm not sure exactly why this is happening but I've specified android:layout_alignParentBottom="true" and android:gravity="bottom" in my (Android) xml layout however the item (HorizontalScrollView containing carousel1) still appears at the top of the layout.
I'm not sure exactly what is wrong in this instance.
Thanks in advance.
Screenshot:
http://i.stack.imgur.com/wefnn.png
<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="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="20dip" >
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageView1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:background="#drawable/main_header_selector"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
I changed the parent LinearLayout to RelativeLayout and in the linearlayout of ScrollView i removed android:layout_alignParentBottom="true" and just added android:layout_gravity="bottom". I hope this will help you. Here is the xml file
<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="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="20dip" >
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageView1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginTop="0dp"
android:background="#drawable/main_header_selector"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
In your HorizontalScrollView, don't use layout_alignParentBottom, use android:layout_gravity="bottom". See LinearLayout.LayoutParams reference guide.
LinearLayout uses layout_gravity for its children, RelativeLayout uses layout_alignX where X is top, bottom, etc. If you wanted, you could keep it as layout_alignParentBottom but the parent of your HorizontalScrollView would need to be a RelativeLayout. Either solution should accomplish the same effect.
Try this layout
<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="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="20dip" >
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have a question about layout android.
This is layout image that i want to make it. Like this:
This is image exmaple:
Here my code:
<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:background="#drawable/first_screen_bg"
tools:context=".LoginActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >
<LinearLayout
android:id="#id/linerTop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="55"
android:background="#color/white"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:id="#id/linerBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="45"
android:background="#color/grey" >
<LinearLayout
android:id="#id/linerMidle"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_gravity="top|center"
android:background="#color/black" >
</LinearLayout>
<RelativeLayout
android:id="#id/linerFlag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="-20dp"
android:background="#drawable/login_flag" >
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout><RelativeLayout>
</RelativeLayout>
But it not running.
Please help me. Thanks
change yout layout.xml to this:
<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:background="#drawable/first_screen_bg"
tools:context=".LoginActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >
<LinearLayout
android:id="#id/linerTop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="55"
android:background="#color/white"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:id="#id/linerBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="45"
android:background="#color/grey" >
<LinearLayout
android:id="#id/linerMidle"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_gravity="top|center"
android:background="#color/black" >
</LinearLayout>
<RelativeLayout
android:id="#id/linerFlag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="-20dp"
android:background="#drawable/login_flag" >
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
I put this code but the problem with the percentage gives me a warning, where shall I put them?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3">
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="14">
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3">
</RelativeLayout>
try as below...
<?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="20" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="3"
android:background="#FF00FF" >
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="14"
android:background="#FFFF00" >
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="3"
android:background="#00FFFF" >
</RelativeLayout>
</LinearLayout>
Right now it splits vertically...I want it to split horizontally. I've looked at everyone else that says theirs cuts horizontally and I can't tell the difference...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
Change your orientation to vertical
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight=".1" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight=".1" >
</LinearLayout>
</LinearLayout>
you should make the sub Views `fill_parent
<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="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
this will create 2 LLinearLayout objects side by side.
if you want to create the one ontop of the other, you should make the android:orientation="vertical" instead
This should work.
<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="0dip"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>