I am creating some TextView, ImageView, HtmlView dynamically and adding it in following layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ad_space"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/navigation_bar"
android:visibility="gone" >
</LinearLayout>
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ScrollView
android:id="#+id/quiz_scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/quizView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/answer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/quiz_scroll_viewTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/quizViewTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/answer_layoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
</ViewFlipper>
</LinearLayout>
In QuizView I am adding some question related views at runtime, and for answers I am creating one list view runtime and adding to answer_layout. I am using BaseAdapter to create ListView runtime based on situation.
But my ListView is not showing all content, its showing only first cell.
I have adding ListView like this.
ListView ansList = new ListView(Test.this);
ansList.setAdapter(adapter);
ansList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
ansCellLayout.addView(ansList);
it display only one list cell.
if I set some int value for height then its show all list contains.
ansList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 600));
But I cant Hardcode list view height as my contant is dynamic.
How to make list view as a WRAP_CONTENT in this scenario ?
According to the Android developers as seen in this Google I/O 2010 video , the ListView's height cannot be set to wrap_content. And when it is , the first three child elements are considered for the height. The others are simply not included.
Try setting the ListView's height at runtime. Or even better set it to FILL_PARENT.
From the documentation a ListView is
A view that shows items in a vertically scrolling list
So it's not supposed to be used with WRAP_CONTENT but rather to have a fixed height and scroll content inside it.
You'd better use a vertical LinearLayout for that purpose.
Related
I created horizontal scrollable listview. And I can populated from db without any problem. The problem is; the entire length of the items are setted to the length of the first item.
Like this
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
</RelativeLayout>
Simple solution to this problem is to use Recyclerview instead of List View.
Adding HorizontalScrollview to LinearLayout will not work.
I have already tried many solutions posted here
after a lot of search I come to this point my solution was Recyclerview.
And from here i learned,How to use this.
You need to make listView height match the parent
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</HorizontalScrollView>
</RelativeLayout>
i am developing an android app where i am showing day wise channel schedule (multiple rows).
now in this i have to provide both vertical and horizontal scrollability.
vertical scrollability will be normal , but horizontal scrollability should be synchronized
that is when user scrolls horizontally all other rows should also be scrolled in a sync.
i tried using table layout but its not going good with my requirement and i have also tried TwoWayView but i am not able to sync the horizontal scrolling.
i would like to know i anyone have faced/solved the similar situation.
Any leads on this is highly appreciated.
xml for vertical and horizontal Scrolling :-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/vertical_scroll_view2">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/horizontal_scroll_view2">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="910dp"
android:id="#+id/scheduleContainer"
android:orientation="vertical"
/>
</HorizontalScrollView>
</ScrollView>
.....
xml for TwoWayView:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/weekday"
android:layout_height="fill_parent"
android:layout_width="40dp"
android:textSize="12dp"
android:textStyle="bold" />
<com.mobiotics.tvb_stb.utilityclasses.TwoWayView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/hlist"
style="#style/TwoWayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/weekday"
android:scrollbars="none"
android:drawSelectorOnTop="false"
tools:context="com.mobiotics.tvb_stb.activity.HomeScreenActivity" />
</RelativeLayout>
i am adding twoway list to linear layout .
If you can have a ListView, I would start there. Just drop the ListView into a HorizontalScrollView. Make sure to set the width of the HorizontalScrollView to wrap_content. I noticed you have it set to fill_parent.
I'd like the top half of my screen to be a graph, and the bottom part to be a listview. Both parts should occupy half of the screen.
With the setup I have now it only works if there are like 10 or more items in the listview. If there are less, the listview will take up less than half the screen. If there's one item in the list, it takes up even less the the height of one list item.
Based on the solution of ANDROID : split the screen in 2 equals parts with 2 listviews this is what I've got now:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.5"
android:id="#+id/graph_container"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.5"
android:orientation="vertical">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
</LinearLayout>
I add the graph dynamically:
((LinearLayout) findViewById(R.id.graph_container))
.addView(chart, 0,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
Does anyone know how I should do this?
UPDATE
So, the essential part was changing the layout_height to math_parent. Removing the parent linear layout of the listview was optional, but definitely cleaner.
Remove container that listView stays in, change the weight to 1 and set height of the main container to match_parent. Here is an example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/graph_container"
android:orientation="vertical">
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:drawSelectorOnTop="false" >
</ListView>
You just have to change your first LinearLayout height to match_parent
Try to use weight values as digits 1:1 fox example.
Setting the android:weightSum="1" and android:layout_height="match_parent" for the parent LinearLayout should work.
i am working with a project in which what i have to do that there are two lists and the layout is very large you can say that it is just double to a normal layout. i have to add scroll view to show whole layout but the problem is that there can't be a list within a scroll view if i do so then there is ambiguity to compiler that which is scrolling if it is list or scroll view . Now what should i do help me thanks in advance ...
I am also attaching an image which is half of my layout....
From your query i designed one sample XML file :
<?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" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffeabc" >
</LinearLayout>
</LinearLayout>
</ScrollView>
In above you will have Scroll View for larger height Views and also you have equal proportion of list View. Thing you have to concentrate is on android:layout_weight , you should check how to play using Weight attributes
Edit :
Okay one thing you can do is that , We can use Header footer concept of List View - make ImageView and 2nd List View as footer of 1st List View so that ImageView and 2nd ListView will always comes Below 1st List View..
For Header Footer concept check this Link.
in my activity, i have three lists. after running the application, the screen is not scroll-able. i can scroll the list which is on top of others but i can't scroll the whole of page. I tried to add ScrollView into my xml layout but lint says that "The vertically scrolling ScrollView should not contain another vertically scrolling widget (ListView)".
How to make my screen scrollable?
Try this way
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/GlobalLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="#+id/ListView1"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="#+id/ListView2"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="#+id/ListView3"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</ScrollView>
Scrollview supports one child layout so make the listview inside the scroll so you will get what you want.
It doesn't work because android don't know with which view he should scroll, so putting a listview in a scrollview its not a bright idea.
try to use visibilty attribute, use to HIDE the view that you finich to work with and set VISIBLE the new.
or use one ListView and try to populate and remove items after finishing and starting an instruction.
hope that help you
What you can do is that you can add header and footer into your list view by inflating them. Create three xml layououts and add them in listview using header and footer.
View headerView = View.inflate(this, R.layout.layout_name, null);
lv.addHeaderView(headerView);
use it before setting adapter. lv is listview.