Grid View inside Scroll View giving issues with number of columns - android

Please help me in this code below :(
I am working on a grid view which should show 4 fixed number of rows in landscape mode. It should display data from an arraylist and should scroll horizontally. I used normal grid view and rotated it by 270. Then inside the grid cell I have used a single Text View which I had to rotate by 90 in order to show the text straight. I set the numColumns property to 4. So the expected is to show 4 rows with data from the arraylist. But I am not getting the grid cell displaying text properky in 4 rows. I am pasting the below xml code for gridview and the single customized xml containing the textview which is inside the gridcell. I tried changing all the properties of the grid view, scroll view and text view. But dont know whats wrong with this code.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView_installed_app" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<GridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:columnWidth="10dp"
android:gravity="center"
android:numColumns="4"
android:rotation="270" >
</GridView>
</LinearLayout>
</ScrollView>
Customized TextView inside gridview cell:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginRight="10dp"
android:id="#+id/textview_gridcell"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:rotation="90"
/>

Related

Android - nested layouts

I have built the following XML 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:background="#color/white"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.3"
android:gravity="center"
android:src="#drawable/logo" />
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.7"
android:gravity="center"
android:text="#string/my_profile"
android:textColor="#A669DA"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:background="#A669DA"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text="#string/payroll_header"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.65" >
<LinearLayout
android:id="#+id/ll3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:weightSum="2" >
<ExpandableListView
android:id="#+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="true" >
</ExpandableListView>
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ExpandableListView
android:id="#+id/expandableListView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ExpandableListView>
</HorizontalScrollView>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
The root element of this XML layout is a linear layout. It contains 2 linear layouts and one scroll. Since scroll view can only have one child, it contains a linear layout which in turn contains an expandable listView, horizontal scrollview (which contains an expandable listview) and a listview. As you can see, this is a very complicated layout, and I think it should be possible to simplify. Basically, I want the top 2 linear layouts to always take 35% of the screen, and the scrollview to take the rest. That's why I gave a weight of 0.2 to the first linear layout, 0.15 to the second linear layout, and 0.65 to scrollView.
Within the scrollView, I would like each of the 3 elements to take as much space as they would need, so that user scrolls down if he/she doesn't see everything. I know that expandableListView and ListView are already scrollable, so I will disable scrolling in them, so that parent's scroll bar is used.
However, I am facing several problems with this design:
1) In the first screenshot, you can see an expandableListView, horizontalScrollBar (with an expandableListView), and a listView.
Each of them has height set to "wrap content", so I would expect each of them to take as much space as they need. However, you can see in the second screenshot that when I open the second expandable listView (the one within a horizontal scrollBar), listview doesn't move down to make space for the expanded list view. How can I achieve it, so that each of them moves down when the expandable list above expands? Is the only way to do it is to combine them all in one expandableListView?
2) My second expandableListView is in the horizontalScrollBar, however, I can't scroll it horizontally. Can I even put horizontal scrollBar inside a vertical scrollBar?
First off, a little simplification: Your second LinearLayout (the 0.15 one) can be left out since it only has a single child. Just be sure to adjust the layout parameters of that single child (the TextView).
For your problem #1, try calling invalidate() or requestLayout() on your root view.
Problem #2 is actually solved: Link
My general impression is that this nesting of ScrollViews and ListViews is pretty complex. Have you considered alternatives such as TabLayout or DrawerLayout?
Cheers

MvxListView not displaying horizontally

In my Android app I've created a vertical layout to hold a horizontal list of images (thumbnails) over top a larger view of a selected image from the list. For some reason I cannot get the horizontal list to display horizontally it only appears as a vertical list.
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="15">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Images"
local:MvxItemTemplate="#layout/image_item" />
</LinearLayout>
<ImageView
android:src="#drawable/BDSeal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="10.0dp"
android:id="#+id/imageView1" />
</LinearLayout>
In Android, the system ListViews are vertical only.
There are open source horizontal list views available - eg cheesebaron once provided http://blog.ostebaronen.dk/2012/12/horizontal-listview-for-mono-for-android.html - and I think this has been updated more recently.
Also some people use the PageAdapter to show this type of horizontally scrolling list.

how to get Horizontal and Vertical Scrollable list in android?

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.

Android List wrap content

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.

how to fit a large layout within a single screen with multiple listviews

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.

Categories

Resources