Scrolling & Layout Problems with ExpandableListView - android

I am developing an app which needs a unscrollable header at the top, Scrollable ExpandableListView in the middle and then unscrollable footer at the bottom. see the image below
The problem is Scrollable property of ExpandableListView, when i expand parent view of the ExpandableListView, list scroll under footer, unscrollable, which is the problem. See below
here's the xml
<?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="#F2B1DBF3"
android:orientation="vertical" >
<include
android:id="#+id/callheader"
android:layout_alignParentTop="true"
layout="#layout/callerheader" />
<ExpandableListView
android:id="#+id/exSavedVoiceList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/callheader"
android:groupIndicator="#drawable/drawableanimation"
android:paddingLeft="10dp" >
</ExpandableListView>
<LinearLayout
android:id="#+id/llbottom"
android:layout_width="match_parent"
android:layout_height="50sp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#ff33b5e5"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/bSaveNewVoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff33b5e5"
android:contentDescription="#string/add_new"
android:drawableLeft="#drawable/setting"
android:drawablePadding="40dp"
android:text="#string/add_new"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
If i put android:layout_below="#+id/exSavedVoiceList" in llbottom (LinearLayout), footer moves below if parent view is expanded.
Please provide a solution with a possible explaination.

// 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:background="#F2B1DBF3"
android:orientation="vertical" >
<include
android:id="#+id/callheader"
layout="#layout/callerheader" />
<ExpandableListView
android:id="#+id/exSavedVoiceList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="#+id/callheader"
android:groupIndicator="#drawable/drawableanimation"
android:paddingLeft="10dp"/>
<LinearLayout
android:id="#+id/llbottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ff33b5e5"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/bSaveNewVoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff33b5e5"
android:contentDescription="#string/add_new"
android:drawableLeft="#drawable/setting"
android:drawablePadding="40dp"
android:text="#string/add_new"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>

Please add android:layout_above="#+id/llbottom" to your expandablelistview. and don't add android:layout_below="#+id/exSavedVoiceList" to your llbottom layout.

Related

Vertical RelativeLayout: how to achieve fixed header and footer and scrollable main area?

This is a layout I'm having problems with (this is for ListActivity):
<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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
<Button
android:id="#+id/negative_button"
style="#style/Button"
android_alignParentBottom="true"
android:layout_below="#android:id/empty"
android:layout_weight="1" />
</RelativeLayout>
What happens right now is the list is below header TextView ("path") as it should be, the button is at the bottom also as it should be, but the ListView is not aligned between the header (textview) and footer (button). Instead, the button is simply slapped on top of listview. How can I fix that?
You need to define the footer and header before the list, try something like 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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<!-- to see the button, you must to declare its width/height here
and not (as I think you did) in the style.xml -->
<Button
android:id="#+id/negative_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Button"
android:layout_alignParentBottom="true" />
<!-- also layout_weight doesnot change anything in RelativeLayout -->
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path"
android:layout_above="#id/negative_button" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
</RelativeLayout>
The TextView "empty" should not be below the TextView "empty".
If the Button must be at the bottom of the screen you can use
android:layout_alignParentBottom="true"
For the Button
Otherwise you can use 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="match_parent" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
</LinearLayout>
<Button
android:id="#+id/negative_button"
style="#style/Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/container" />
</RelativeLayout>
Or ever add the Button as a footer of you Listview :
mListView.addFooterView(mButton);
http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
The only things that you used are the ListView, the first TextView as a "top bar" and the Button as a "bottom bar", right? If it is the case, why did you keep the empty TextView?
Try to remove it and try this layout:
<?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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<!-- work also with android:layout_height="0dip" -->
<Button
android:id="#+id/negative_button"
style="#style/Button"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Saw on these questions, it might be help you:
1. Layout for ListView at top and Buttons in Bottom?
2. Android Layout with ListView between a "top bar" and "bottom bar"
3. Add a button in bottom of listview when the listview is empty (using ListActivity)
Hope this will be helpful and you'll have the expected result.

Align a layout on top, inside other layout

I have 2 fragments, the first had the second inside it. This is the first:
<?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="#drawable/gradient_details_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/fragmentDetailTitle"
style="#style/textTitleDetailStyle" />
<LinearLayout
android:id="#+id/detailSubObjectFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/fragmentDetailButtonGo"
style="#style/goButtonStyle" />
</RelativeLayout>
And inside the layout detailSubObjectFrame I had others fragments. In this specific case:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sub_take_error_Layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<LinearLayout
android:id="#+id/numberErrorLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal" >
<com.mypackage.NumberPickerCustom
android:id="#+id/numberPickerCustomRandom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
max="100"
min="1"
value="30" />
<TextView
android:id="#+id/moreText"
style="#style/textOnSubmenu"
android:textSize="20sp"
android:text="#string/moreErrorText" />
</LinearLayout>
<LinearLayout
android:id="#+id/myLayoutTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/numberOfQuestion"
style="#style/textOnSubmenu"
android:textSize="20sp"
android:text="#string/numberOfErrorQuestionText" />
<TextView
android:id="#+id/numberOfQuestionValue"
style="#style/textOnSubmenu"
android:textSize="20sp"
android:text="6" />
</LinearLayout>
</RelativeLayout>
I would like that the layout "myLayoutTop", will be placed just below the textview of the first fragment fragmentDetailTitle. (Without moving the other layout from the center).
Like you can see I tried layout_alignParentTop but didn't work.
If needed I could totally change only the layout of the 2nd fragment, the constraint that I have is that numberErrorLayout should stay (like now) on the center of the screen.
I just changed the layout of detailSubObjectFrame in a FrameLayout and sub_take_error_Layout in a LinearLayout. After I used the attribute gravity for numberErrorLayout and myLayoutTop.

android Layouts overlapping ListView and LinearLayout

I am using FrameLayout in which I am having a search Textbox and Button and a ListView to be displayed in the next line of the TextBox
My layout is like this ,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/pattern1" />
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="top" >
<Button
android:id="#+id/btnadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="addCustomers"
android:text="Add"
android:textColor="#000000" >
</Button>
<EditText
android:id="#+id/edtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:hint="Search"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="60dp"
android:gravity="bottom"
android:orientation="vertical">
<ListView
android:id="#+id/list_customers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" >
</ListView>
</LinearLayout>
</FrameLayout>
I am using this TextView to diplay List item in the ListView,
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txtsimple_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_vertical"
android:textSize="20sp"
android:textStyle="bold" />
I have given margin top attribute for the ListView, but even though it overlaps on the Button and EditText controls.
I am using a FrameLayout but of no use. Please suggest me any help!!
Any help is appreciated!!
You should use LinearLayout as parent, just set android:orientation="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" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/pattern1" />
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="top" >
...
</LinearLayout>
<ListView
android:id="#+id/list_customers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" >
...
</ListView>
</LinearLayout>
FrameLayout has no 'rules of placement' so everything just stacks on to each other.
Instead, use a LinearLayout with android:orientation="vertical"
or use a RelativeLayout and add positioning values to the childs, such as android:layout_below
+1 Neoh and remove imageview, instead put the image as background image attribute at parent view
android:background="#drawable/pattern1"
FrameLayout are used very less,beacuse they are used to display single view or views which overlaps each other.
So you should use RelativeLayout.
FrameLayout is not the best option. You can use other layouts, eg, GridLayout, RelativeLayout or ListView.

Android, LinearLayout won't scroll

I am relatively new to android programing. Can anybody tell me why my ScrollView won't scroll?
My activity has implemented OnGestureListener for getting some touch information. But, I tried to disable onGestureListener and it still won't work.
It works outside of the SlidingDrawer. Is it possible to get it work inside of the SlidingDrawer?
I solved it by giving to ScrollView ID and then put that ID in SlidingDrawer android:content="#+id/content".
<?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:layout_gravity="right"
android:background="#drawable/pozadina_touchpad"
android:orientation="vertical" >
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="vertical" >
<SlidingDrawer
android:id="#+id/prosirenje"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gumb_slider"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/slider"
android:gravity="center"
android:onClick="nemaSkrola"
android:orientation="vertical" >
<Button
android:id="#+id/ico_povecalo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_povecalo" />
<Button
android:id="#+id/ico_desktop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_komp" />
<Button
android:id="#+id/ico_daljinski"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_play" />
<Button
android:id="#+id/ico_tipkovnica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_tipka" />
<Button
android:id="#+id/ico_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_settings" />
</LinearLayout>
</ScrollView>
</SlidingDrawer>
</LinearLayout>
</LinearLayout>
give some value to scrollView's width and height and try like this
<ScrollView
android:id="#id/content"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
please change scrollview id like this:
android:id="#id/content"
please change handle button id like this:
android:id="#id/handle"
The containers (hierarchical parents) of the ScrollView have the following attribute set this way: android:layout_height="match_parent", which forces them to limit their content to the height of the activity (screen).
For your ScrollView to work, try to get the ScrollView to a higher hierarchical level, so that won't be constrained by its parent.

Last two items of a fragments Listview not showing when a footer is present

Good day, I have an Activity which contains 4 fragments. The Activity has a footer which I use to switch between these fragment views. Now in one of my fragments, i have some widgets and the last widget is a ListView. The trouble am having is, the last 2 entries in the Listview are not displaying correctly! they are obscured by the footer. I have set my LayoutParameters for both the width and height of the Listview to FILL_PARENT. but its not working. Any idea how i can solve this? Thanks in advance.
My Layout is :
for the fragment:
<?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">
<Button android:id="#+id/line_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_marginLeft="5dp" android:focusable="true"
android:layout_marginTop="8dp" android:text="#string/line_graph" android:background="#drawable/temp_left_button" />
<Button android:id="#+id/bar_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignBaseline="#+id/line_button_id"
android:layout_alignBottom="#+id/line_button_id" android:focusable="true"
android:layout_alignParentRight="true" android:layout_marginRight="5dp"
android:text="#string/bar_graph" android:background="#drawable/temp_right_button"></Button>"
<FrameLayout
android:id="#+id/graph_framelayout_id"
android:layout_width="fill_parent"
android:layout_height="280dp"
android:layout_below="#id/line_button_id"
android:padding="4dp"
android:layout_margin="4dp"
android:background="#drawable/rounded_date_filter">
</FrameLayout>
<!-- first cell information, dashboard -->
<LinearLayout
android:id="#+id/row1_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_below="#id/graph_framelayout_id"
android:orientation="horizontal"
android:clickable="true"
android:background="#drawable/rounded_table_row">
<TextView
android:id="#+id/dashboard_datefrom_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="01 may 2012"/>
<ImageView
android:id="#+id/dashboard_image_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_action_search"/>
<TextView
android:id="#+id/dashboard_dateto_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="01 sept 2012"/>
</LinearLayout>
<!-- accounts overview listview -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row1_id"
android:layout_margin="4dp"
android:orientation="vertical"
android:background="#drawable/rounded_date_filter">
<TextView
android:id="#+id/list_text_header_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="#string/data_grid_text_header_day"
android:background="#drawable/text_header">
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</RelativeLayout>
and for the Activity i have this:
<
?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" >
<FrameLayout
android:id="#+id/fragment_container_id"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<include layout="#layout/footer"></include>"
</RelativeLayout>
i replace the fragments with in the framelayout of the Activity
What Layout are you using in your Fragment, this surely won't happen if you use RelativeLayout and set above attribute to your ListView like this :
Try to add this into FrameLayout in your Activity layout.
android:layout_above="#+id/footer"

Categories

Resources