In my android application i have an expandableListView and Listview. In ListView I am getting data from Webservice. Then data loads into ListView some kind of overlap between ExpandableListView and ListView Items i want to one of them is hiding under other. How can I achieve it?
Please find below the image of my application.
My Xml code
<?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"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<GridView
android:id="#+id/listView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</GridView>
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="wrap_content"
android:layout_height="135dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:divider="#00000000"
android:groupIndicator="#drawable/group_indicator"
android:stackFromBottom="true" >
</ExpandableListView>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/listView1"
android:layout_marginTop="37dp"
android:divider="#00000000"
android:listSelector="#android:color/transparent" >
</ListView>
</RelativeLayout>
Please note that you are using GridView not ListView at least in this code, your ListView is commented currently.
Now if you want to have ExpandalbleListView below ListView add
android:layout_below="#id/listView1"
to your ListView. You are using RelativeLayout and this layout create as z-axis making it possible to overlap view over each other. So, in RelativeLayout you have to specify where a view should be positioned with respect to other `views.
Try this.
<?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:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<GridView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="0.4"
android:divider="#00000000"
android:stackFromBottom="true" >
</ExpandableListView>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="0.2"
android:divider="#00000000"
android:listSelector="#android:color/transparent" >
</ListView>
</LinearLayout>
Related
My grid design is as such. But i want to remove the spaces on both sides of the grid elements. (Black marked)
I want the image to be expanded somewhat like
My XML layouts for the gridview
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity" >
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dip"
android:gravity="center"
android:numColumns="2"
android:stretchMode="spacingWidthUniform" />
</LinearLayout>
My grid element 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" >
<ImageView
android:id="#+id/grid_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:contentDescription="#string/im" >
</ImageView>
<TextView
android:id="#+id/grid_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="23"
android:gravity="center"
android:layout_marginTop="10sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="12sp" >
</TextView>
</LinearLayout>
Try Changing
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:background="#abcdef"
android:stretchMode="columnWidth" />
You can replace GridView with GridLayout and use weights to make the images fill the screen. Here's the reference: http://developer.android.com/reference/android/widget/GridLayout.html, (See the section: Excess space distribution)
Hi in my application I am displaying image and text by using grid view for that i used frame layout inside linear layout.
Now i want above the list view i want to display some image.
can anyone please help me.
xml
<?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" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<com.agilerise.hotel.SquareImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:paddingTop="50dp"
android:paddingBottom="50dp"
/>
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_gravity="bottom"
android:textColor="#android:color/black"
/>
</FrameLayout>
<GridView
android:id="#+id/buttom"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:numColumns="3"
android:layout_weight="1">
</GridView>
</LinearLayout>
add list view in your xml
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.68" >
</ListView>
and create item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/ic_avatar"
android:scaleType="centerCrop"/>
</LinearLayout>
Then you should use ArrayAdapter in your activity class to create your listview...
I see the scroll line but it is not working. This is the code:
What could be the reason?
The layout:
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/titleshopandsell"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:text="פריטים שתוכל למכור"
android:textColor="#880000"
android:textSize="12sp" />
<GridView
android:id="#+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:verticalSpacing="3dp"
android:horizontalSpacing="2dp"
android:columnWidth="130dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
</LinearLayout>
</ScrollView>
What is the problem with my code?
GridView is also a special type of ScrollView.. you should change parent scrollView to Relative/Linear Layout.
Currently Both scrollView and GridView obstruct the proper scrolling.
i'm trying display two listviews in a fragment. but i'm getting problems in xml file itself. I am using sherlock fragment.
Also one list should be displayed on 2/3 space of the screen and another list on 1/3 of the screen space. please can u help? Any help would be appreciated. Thanks in advance.
<?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"
android:background="#DEF7C6"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="60dp"
android:layout_height="35dp"
android:paddingLeft="0dp"
android:src="#drawable/search" />
<EditText
android:id="#+id/EditText01"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="Search"
android:paddingLeft="50dp"
android:textColor="#000000" >
</EditText>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/EditText01"
android:drawSelectorOnTop="false"
android:listSelector="#android:color/darker_gray" >
</ListView>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#CFCACC" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout1"
android:layout_weight="2" >
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#000000" />
</RelativeLayout>
<Button
android:id="#+id/addbutton"
android:layout_width="42dp"
android:layout_height="41dp"
android:layout_above="#+id/list"
android:layout_alignParentRight="true"
android:background="#drawable/buttonadd" />
</RelativeLayout>
Here's the code for the ListViews only:
<?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="#DEF7C6"
android:orientation="vertical" >
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:drawSelectorOnTop="false"
android:entries="#array/l1"
android:listSelector="#android:color/darker_gray" >
</ListView>
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:entries="#array/l2"
android:listSelector="#android:color/darker_gray" >
</ListView>
</LinearLayout>
Note the "weight" parameter to achieve the 2/3 - 1/3 proportion. You should look here if you want to add list view elements dynamically.
If you want other elements instead of the second ListView just change it for a LinearLayout or a RelativeLayout.
My ListView does not receive onScroll events in case it is short and does not fill the whole screen, which is strange, because I have set fill_parent as height.
My 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="#drawable/bg_login_screen3"
android:orientation="vertical" >
<CheckBox
android:id="#+id/overview_allcars_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/all_cars"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/list_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:fadingEdge="horizontal"
android:scrollingCache="true" />
</LinearLayout>
</LinearLayout>
You may find this answer useful:-
Making TextView scrollable on Android
Thats what helped me there:
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:id="#+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</ScrollView>
Mainly you wrap your TextView in a ScrollView.