Here is my xml file for my layout:
<com.handmark.pulltorefresh.library.PullToRefreshScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pull_to_refresh_scrollview_feat"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listViewFriends"
android:layout_width="match_parent"
android:layout_height="1100dp" >
</ListView>
<ListView
android:id="#+id/listViewTrending"
android:layout_width="match_parent"
android:layout_height="1100dp" >
</ListView>
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
For some reason, the only way to show both ListViews is by setting height in actual dp's. I can't use wrap_content or layout_weights.
Is this a limitation of using multiple ListViews? Or am I doing it wrong?
I simply scrapped this idea and used a MergeAdapter and got what I was looking for.
I assume PullToRefreshScrollView is some sort of ScrollView. You should not use a ListView inside a ScrollView; they just do not play well together. Not only must you must set an explicit layout height for the list(s), but the two views will get in each other's way in dealing with touch events.
If you promote the LinearLayout to the top of the container hierarchy, you can set the following attributes for each ListView:
. . .
android:layout_height="0dp"
android:layout_weight="1"
. . .
They should then take up the same vertical space.
I have not tried this, but could you set layout_height=0dp and layout_weight=1 to your ListViews and see what happens?
Hope it helps.
Related
My XML file has a LinearLayout containing two ListView with android:height="wrap_content". However, when one of the ListView has too much contents, it pushes another ListView and eat up its space. What can I do to make it stops pushing at certain height? I've tried adding layout-weight or maxHeight but it doesn't help.
If you want the same amount for both ListViews equally divided, just put them in a LinearLayout.
LinearLayout will have property weightSum=2 while both ListViews will have, depending on the LinearLayout orientation property:
If vertical -> both ListViews will have android:height="0dp" and layout-weight=1
If horizontal -> both ListViews will have android:width="0dp" and layout-weight=1
I solved it by doing it programmatically. It seems XML doesn't give much control for dynamic height. I added onLayoutChangedListener to both ListView to detect height change and add height control logic in the listener.
Try this :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/green_bg_duplicate"
android:gravity="center"
android:orientation="vertical"
android:weightSum="2">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1" />
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1" />
</LinearLayout>
My Layout has a few complex layouts and they are pretty big. That's why I need a ScrollView. But whatever I try it doesn't work.
Here is my layout file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:id="#+id/Linear1"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#color/tileColor1"
android:layout_weight="1"
android:id="#+id/tileLayout1"
android:onClick="openFirst"
>
I have only posted a part of it but all the closing tags are ok and inside my RelativeLayout there are 2 textViews and an image. There are 9 more RelativeLayouts with the same structure.
How can I fix the problem and why doesn't it work? It doesn't even show a scrollbar.
EDIT
I have uploaded my full layout to pastebin
EDIT 2
On the developer.android it is said:
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Mine doesn't deal with the scrolling at all. I suppose it is this way because I edit LayoutParams in code. How do I fix this?
1. Try removing android:layout_weight="1" and android:orientation="vertical".
2. Ensure that there is only one ViewGroup inside the ScrollView (i.e. one child as they say). I assume you've done this, but as you haven't provided your full layout I couldn't confirm it.
ScrollView only accepts one child view. So wrap everything inside it in a LinearLayout with wrap_content set as height and you're set.
I had the same problem, and I do not know if my solution helped (mainly because it is a very late response), but my ScrollView not worked since set up a layout that fit exactly on the screen, so it was not necessary to create scrolling. When increased my layout (I put all my items with
android:layout_height = WRAP_CONTENT) became operational.
I tried to search everywhere for what I got stuck on it here, the issue is the scrollViewI have two problems with the scrollView:The first problem;The scrollView not give all of the content that has,I tried to add the following line: android: fillViewport = "true"But it did not helpĀ Second problem;Full content shown leaving the space at the end and ends at the end of scrollView content
enter code here
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
android:layout_weight="90"
android:padding="15dp"
android:id="#+id/scroll_view"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
>
....
Thanks to those who could help me...
Do you need to set layout_weight in your ScrollView?
If not remove this line or set it's value to 1.
Also change the layout_width & layout_height to fill_parent in the child view.
I first posted this as a comment, but since it solved the problem, I'll post it as an answer instead.
The attribute android:orientation does not apply to ScrollView; you should remove it. Also, you should remove the android:layout_gravity="center_vertical" attribute in the child view; it's not appropriate for the child of a ScrollView.
I have a really annoying problem with fitting two custom views to work together. I'm trying to display these two views in an android activity, but one of them takes the whole viewable space of the activity and the other is placed under it. The first view only uses a small part of the space and the rest is trasparent, but it only works when its width and height is at match_parent so the other view is displayed under it, but it is being blocked from receiving any touch events. here is how they looks like:
the xml code:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_app" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/example_lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both"
android:focusableInTouchMode="true"/>
</LinearLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:padding="1dip" />
</FrameLayout>
What I'm trying to do is to be able to touch the bottom where the top view is transparent, and be able to touch the top view where it's not transparent. I tried arranging the xml in a different way but it keeps crashing, this is the only way it worked, but this problem appeared.
Links to the custom Views:
Radial-Menu-Widget: github.com/strider2023/Radial-Menu-Widget-Android
SwipeListView library: github.com/47deg/android-swipelistview
SwipeListView sample: github.com/47deg/android-swipelistview-sample
What I'm trying to accomplish here is something similar to Catch Notes app. If there are other ways, or other libraries you can suggest, it would be much appreciated.
Ok try this: copy the source code of SemiCircularRadialMenu.class in your project and modify
public boolean onTouchEvent(MotionEvent event)
Because this method always returns true and captures all touch events, so also the touch event for SwipeListView listener. I solved it in this way.
An old question, but others may find this answer helpful. Without modifying the source of your custom views, I don't think you can get the behavior you want. But getting the two custom views to work onto the same screen might be as simple as changing your root layout to a LinearLayout, adding weight to the inner layout, and setting the height of the second custom view to wrap_content. By having only one widget with a weight, it will get all the space left after the others are laid out. Here's your layout with the changes applied:
<?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="#color/background_app"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="100" >
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/example_lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusableInTouchMode="true"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both" />
</LinearLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="1dip" />
</LinearLayout>
If you need to height of the second view to be more expandable, you can wrap it in another LinearLayout with a weight and adjust the two weights to apportion the screen height between them. The individual weight values aren't special; it's their value relative to the sum of all the weights that determines how much height each one gets. I like to make my total values add up to 100 so I can think of the weights as percentages.
I have problem in this layout that : it doesn't show any child after the listView
and the listview is filling this sight ; it scrolls but didn't show the any other child
I have tried to user ScrollView but it make issues with expandlist
this is layout xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/select_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/Header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_bg"
android:gravity="center"
android:paddingRight="50dip"
android:paddingTop="5dip"
android:text="#string/select"
android:textColor="#60240a"
android:textSize="18dip"
android:textStyle="bold" >
</TextView>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent"
android:divider="#drawable/line_divider"
android:dividerHeight="3dip"
android:listSelector="#android:color/transparent" >
</ListView>
<ImageView
android:layout_width="fill_parent"
android:layout_height="3dip"
android:src="#drawable/line_divider" />
<ExpandableListView
android:id="#+id/expandableList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent"
android:childDivider="#drawable/line_divider"
android:divider="#drawable/line_divider"
android:dividerHeight="2dip"
android:listSelector="#android:color/transparent"
android:textColor="#60240a" >
</ExpandableListView>
</LinearLayout>
When you are using ListView in the layout you have to add this property android:layout_weight for the listview. Without this property being set, you cannot get all views.
Since your layout is linear any views that exceeds the limit of the screen are not displayed in the screen. Yes scrollview makes issues with list or expandable listview as the scrollview itself is scrollable it will consume the scrolls of listview and expandablelist. To resolve this you have to re order or change your layouts to make your rest of the views visible
Give the first ListView some constant height. Like
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="300dip"
....
/>
LinearLayout will not scroll when its content increases. And you cannot use a ScrollView as parent for ListView.
Set all layout_height - attributes from direct childs of your root layout to fill_parent.
Than give every of these layouts a attribute layout_weight.
The value of layout_weight is an integer according to how many space they've been granted in the view.
For example two views: one with weight 2 and one with weight 1: The weight 1 is twice the size of weight 2.
Just play a little with the weight attribute to find out for yourself.
You have given height of listview as wrap_content so it will occupy the all the space in screen so u give the height of listview fixed and same thing applied to expandable list also give fix height to that also.
Hope u get it All The best