In reference to this question. I have hit a wall, I have both of my adapters set up, and my xml files are nicely lined up. In my activity I have set my content view to the main xml which contains the top gridview. In the adapter I have linked my Imageview to the gridview.
The problem is how do I go about setting the grid_item.xml as my contentview for the inner adapter so that I can link the next image view to the xml?
These are my xml files in order:
main_layout.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" >
<GridView
android:id="#+id/gridview_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:columnWidth="60sp"
android:gravity="center"
android:horizontalSpacing="10sp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10sp"
android:clipChildren="true" />
</LinearLayout>
grid_item.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" >
<ImageView
android:id="#+id/category_main_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_left_dark" />
<GridView
android:id="#+id/gridview_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:columnWidth="90sp"
android:gravity="center"
android:horizontalSpacing="10sp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10sp"
android:clipChildren="true" />
</LinearLayout>
item_grid_image.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" >
<ImageView
android:id="#+id/item_main_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_left_dark" />
</LinearLayout>
I need to get the content of my grid_item.xml for my inner adapter. Any ideas?
Ended up settings views (views with images) dependant on the amount of children. Adding a gridview to each gridview element ended up messing up scrolling :).
I'm trying to display some items in a GridView. I want each item to fill a relative part of the screen (image B) and all I have is GridView take just the space it needs at the top of the screen (image A). The image:
(I want each item sizes over 15-20% height of the main layout)
EDIT : I found this question Percentage width in a RelativeLayout. 'LadaRaider' gives a good answer but I don't know how to use that solution in my GridView cells. This is my layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<TextView
android:id="#+id/label_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal"/>
<LinearLayout
android:id="#+id/ll_ok"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lbl_choose"
android:textAppearance="?android:attr/textAppearanceMedium" />
<GridView
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:columnWidth="100dp"
android:stretchMode="columnWidth"/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_wait"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lbl_wait"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
I have also created a custom layout to use in GridView items. It has just a TextView and a background.
I am displaying a TextView and below that a ListView in one page. My code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="#+id/widgetlay"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt1"
android:text=""
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
</TextView>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:id="#+id/listlist"
android:layout_height="0dp"
android:layout_weight="1.0">
</ListView>
</RelativeLayout>
Here I am displaying the ListView data dynamically....but in my emulator it is displaying a TextView at the top and then the ListView with scroll...It is not expanding the list and instead it is scrolling with the content which is generated dynamically...Please tell me how to expand the entire ListView....
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:gravity="center|center_vertical"
android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/txtvw1">
</TextView>
<ListView
android:layout_width="fill_parent"
android:id="#+id/listlist"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</LinearLayout>
<?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/txtvw1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">
</ListView>
</LinearLayout>
You have an error here
<ListView
android:layout_width="fill_parent"
android:id="#+id/listlist" //error here
android:layout_height="fill_parent">
</ListView>
the ListView is filled of the LinearLayout
so that you can't get the TextView.
instand of this
you can layout your view as follows:
<ListView
android:layout_width="match_parent"
android:id="#+id/listlist" //error here
android:layout_height="0"
android:layout_weight="1.0>
android:layout_weight="1.0" //this will make the list view filled with the rest of the screem
Further more
I suggest you use "match_parent" instand of "fill_parent"
this WAS CHANGED in the SDK level 8...
OK, now you use the RelativeLayout install of the LinearLayout
So you should add the relationship with your views in your layout.
You can layout as this:
<RelativeLayout
android:id="#+id/widgetlay"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txt1" />
android:layout_below="#id/txt"----Indicate the relationship with the layout
The RelativeLayout does not have the attr "orientation" and "layout_weight". So I don't suggest you to use this layout, It can't be fixed with the screen height in that way.
The good layout is:
<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:id="#+id/txtvw1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="status" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
Further more, what do you want to layout your views?
This is a part of my work. List view will appear in the middle of your screen and what ever u need at the top, put it in place of header() and things that u need in bottom of the screen , put it in place of footer(). U can use relative layout instead of the linear layout
Hope this helps.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_height="wrap_content" android:id="#+id/layout_header">
<include layout="#layout/header"/>
</RelativeLayout>
<LinearLayout android:layout_width="match_parent" android:gravity="center" android:orientation="horizontal" android:weightSum="1"
android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="#+id/layout_footer">
<include layout="#layout/footer" />
</LinearLayout>
<ListView android:id="#android:id/list" android:layout_below="#id/layout_header" android:layout_above="#id/layout_footer"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="visible" />
<!-- <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/> -->
</RelativeLayout>
I don't know what is meaning of expanding meaning here, but listView in scroll view dont behave normally. To resolve this issue you need to implement list view outside of scrollview.
I don't quite understand what you mean, but if you want to have the textView scroll with the content of the listView, you need to add it as a header in your listView.
Moreover, it is not a good idea to put a listview in a scrollview, the listview being scrollable, it messes with the scrollview mechanism.
You can NEVER ever place a listview in the SCrollView.It wont behave properly.Instead of it try using LinearLayout TextView ListView < /Linearlayout>
I am creating a calendar using GridView (6 row * 8 column). Each of the cells inside this matrix (6*8) is a TextView (which I create dynamically in my program).
The issue I am facing is, the 6*8 matrix is not filling the entire space available for GridView
I would like to to have the 6*8 matrix take the entire space in GridView rather than leaving some blank space b/w the matrix and the next TextView. Can some one help me on this.
Given below is the xml layout of the Gridview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="8"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:id="#+id/id_worked"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Result 1 ->"
android:layout_weight="0"
android:textSize="20sp"
/>
</LinearLayout>
Remove the
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
from the GridView element. That shoudld reduce the spacing.
Edit: Using LinearLayout you can do this.
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1"
android:weightSum="6">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
</LinearLayout>
I am developing an application.I have 2 buttons in it back and item.I want to place a list below the buttons.How can i do this in xml file?Can anyone tell me...
try below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" android:background="#drawable/background">
<LinearLayout
android:id="#+id/LinearLayoutIcons"
android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal">
<Button android:text="#+id/Button01" android:id="#+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button><Button android:text="#+id/Button02" android:id="#+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
<ListView
android:id="#+id/ListViewMessage"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
If you want to align a list view below Button01
try
android:layout_below="#+id/Button01"
in the ListView