Layout not appear right in runtime - android

I use monodevelop ti android developing. I wanna add a loading item in end of my list that is loading from internet.
I use this xml file for this propose:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="125dp">
<RelativeLayout
android:id="#+id/LoadingRealtive"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="#drawable/List_Menu_Bg"
>
<ProgressBar
android:id="#+id/loadingListItems"
style="#style/GenericProgressIndicator"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loadingListItems"
android:id="#+id/textView1"
android:layout_centerHorizontal="true"
android:textColor="#6b6b6b" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/MainRelative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="#drawable/List_Menu_Bg">...MyListItems </RelativeLayout></LinearLayout>
and in View of my list used this code:
public override View GetView (int position, View convertView, ViewGroup parent)
{
View vi = convertView;
try {
if (convertView == null)
vi = activity.LayoutInflater.Inflate (Resource.Layout.list_row, parent, false);
RelativeLayout LoadingRelative=(RelativeLayout ) vi.FindViewById (Resource .Id.LoadingRealtive);
RelativeLayout ContentRelative=(RelativeLayout ) vi.FindViewById (Resource .Id.MainRelative );
if(Data [position ] == null)
{
ContentRelative .Visibility =ViewStates.Gone ;
LoadingRelative .Visibility = ViewStates.Visible ;
}else{
ContentRelative .Visibility =ViewStates.Visible ;
LoadingRelative .Visibility = ViewStates.Gone ;<...MyListCodes...>
}
} catch (Exception ex) {
Common.HandleException (ex);
}
return vi;
}
It work fine.just problem is that the loading layout loads wrap_content while it must load fill_parent.
I don't understand why it is?
can any body help me?

when use linearlayout as a wrapperview, you should give android:weight to its chield views which has fill_parent attribute.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="125dp">
<RelativeLayout
android:id="#+id/LoadingRealtive"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="#drawable/List_Menu_Bg"
android:weight="1"
>
<ProgressBar
android:id="#+id/loadingListItems"
style="#style/GenericProgressIndicator"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loadingListItems"
android:id="#+id/textView1"
android:layout_centerHorizontal="true"
android:textColor="#6b6b6b" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/MainRelative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="#drawable/List_Menu_Bg"
android:weight="1" >
</RelativeLayout>

Related

GridView with image and text

I'm very new in android and need a little help with this task.
I have gridview witch pull images and text from database and display them. Currently is displayed like image and on the right of the image is text. I want to make text under the image. Can you help me with this task. This is the gridview.xml
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1" >
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:numColumns="2" >
</GridView>
</LinearLayout>
And this is how I display image and text in it table_column.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bckimageviw"
>
<ImageView
android:id="#+id/ColPhoto"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/ColName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Name"
/>
</LinearLayout>
</LinearLayout>
And if need getView()
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.table_column, null);
}
// ColPhoto
ImageView imageView = (ImageView) convertView.findViewById(R.id.ColPhoto);
imageView.getLayoutParams().height = 80;
imageView.getLayoutParams().width = 80;
imageView.setPadding(10, 10, 10, 10);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
try
{
imageView.setImageBitmap((Bitmap)MyArr.get(position).get("ImageThumBitmap"));
} catch (Exception e) {
// When Error
imageView.setImageResource(android.R.drawable.ic_menu_report_image);
}
// ColName
TextView txtName = (TextView) convertView.findViewById(R.id.ColName);
txtName.setPadding(5, 0, 0, 0);
txtName.setText("" + MyArr.get(position).get("name").toString());
return convertView;
}
u can use relative layout and set align textview to imageview.
try this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:gravity="center" >
<ImageView
android:id="#+id/ColPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ColName"
android:layout_alignRight="#+id/ColName"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/ColName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ColPhoto"
android:gravity="center"
android:text="Name name" />
</RelativeLayout>
I don't know why add a single element LinearLayout in another LinearLayout.
if grid item need to be put in correct position, I'd like use RelativeLayout instead.
`
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/ColPhoto"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<TextView android:id="#+id/ColName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ColPhoto"
android:text="Name"
/>
</RelativeLayout>
`
Try to change your orientation to "vertical".
EDIT:
Like, Tr4X said you don't need second LinearLayout. You can put both in one.
<?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/bckimageviw" >
<ImageView
android:id="#+id/ColPhoto"
android:layout_width="0dp"
android:layout_height="0dp"/>
<TextView
android:id="#+id/ColName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
</LinearLayout>

Listview title in Alphabet Indexer displayed wrongly

I am trying to implement a Listview with alphabet indexing . I succeed in displaying it but the problem is the text in Listview goes inside the alphabets rather than displaying horizontally. Please help . Song name went inside the alphabet indexer. Pasting below the xml file and code:
List item xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="songPicked"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/sort_key_layout"
android:layout_width="fill_parent"
android:layout_height="18dip"
android:background="#EAEAEA" >
<TextView
android:id="#+id/sort_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dip"
android:textColor="#000000"
android:textSize="13sp" />
</LinearLayout>
<TextView
android:id="#+id/tv_song_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
Listview xml:
<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" >
<FrameLayout
android:id="#+id/title_layout"
android:layout_width="fill_parent"
android:layout_height="18dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:background="#EAEAEA" >
<TextView
android:id="#+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dip"
android:textColor="#000000"
android:textSize="13sp" />
</FrameLayout>
<LinearLayout
android:id="#+id/indexer_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical" >
<ListView
android:id="#+id/lv_song_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#null"
android:paddingLeft="5dp"
android:paddingRight="5dp"
>
</ListView>
</LinearLayout>
</RelativeLayout>
Adapterclass:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.d(this.getClass().getName(), "inside getview");
if(convertView == null) {
Log.d(this.getClass().getName(), "inside if getview & position is"+position);
convertView = songInf.inflate(R.layout.song, null);
holder = new ViewHolder();
holder.sortKeyLayout = (LinearLayout) convertView.findViewById(R.id.sort_key_layout);
holder.sortKey = (TextView) convertView.findViewById(R.id.sort_key);
holder.songName = (TextView) convertView.findViewById(R.id.tv_song_title);
holder.songArtist = (TextView)convertView.findViewById(R.id.tv_song_artist);
convertView.setTag(holder);
} else {
Log.d(this.getClass().getName(), "inside else getview & position is"+position);
holder = (ViewHolder) convertView.getTag();
}
Song currSong = songs.get(position);
holder.songName.setText(currSong.getTitle());
holder.songArtist.setText(currSong.getArtist());
int section = mIndexer.getSectionForPosition(position);
if (position == mIndexer.getPositionForSection(section)) {
holder.sortKey.setText(currSong.getSortKey());
holder.sortKeyLayout.setVisibility(View.VISIBLE);
} else {
holder.sortKeyLayout.setVisibility(View.GONE);
}
return convertView;}![enter image description here][1]
I guess the problem is with your layout Listview xml you are using relative layout they will obviously overlap each other until or unless you place them relative to each other.
You have to take out your lv_song_list from indexer_layout
You can refer
<FrameLayout
android:id="#+id/title_layout"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:background="#a86bf0"
android:visibility="gone" >
<TextView
android:id="#+id/title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dip"
android:textColor="#000000"
android:textSize="13sp" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="10" >
<ListView
android:id="#+id/indexed_listView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:cacheColorHint="#null"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<LinearLayout
android:id="#+id/indexer_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" />
</LinearLayout>
<RelativeLayout
android:id="#+id/section_toast_layout"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerInParent="true"
android:background="#drawable/black_base_rounded_transparent_50_rad2"
android:visibility="gone" >
<TextView
android:id="#+id/section_toast_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="#style/text_white_medium_franklin_bkcd"
android:textSize="30sp" />
</RelativeLayout>

Two ListViews inside a Linear Layout

PLease help me with layout of the two list views placed vertically in the Linear Layout. Problem is that if list1 had more data than list2 is not visible and it not scrollable, using scollview is not solution.
<?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="#drawable/backrepeat"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_calendar_top"
android:orientation="horizontal" >
<ImageView
android:id="#+id/prevMonth"
android:layout_width="50dp"
android:layout_height="55dp"
android:src="#drawable/button_events_previous" >
</ImageView>
<TextView
android:id="#+id/currentMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.6"
android:gravity="center_vertical|center_horizontal"
android:text="Janauary"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#d458b1"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="#+id/nextMonth"
android:layout_width="50dp"
android:layout_height="55dp"
android:src="#drawable/button_events_next" />
</LinearLayout>
<TextView
android:id="#+id/direction_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:background="#DA81F5"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="PRESS RELEASES"
android:textColor="#FFFFFF"
android:textSize="13dip" />
<ListView
android:id="#+id/eventsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/direction_label"
android:background="#ffffff" >
</ListView>
<TextView
android:id="#+id/direction_label1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#DA81F5"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="SPEECHES"
android:textColor="#FFFFFF"
android:textSize="13dip" />
<ListView
android:id="#+id/eventsList1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/direction_label1"
android:background="#ffffff" >
</ListView>
<TextView
android:id="#+id/empty_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
If I use the scrollview then it is wrapping up the listview for only first row.
Please suggest something.
EDIT :
<?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="#drawable/backrepeat"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_calendar_top"
android:orientation="horizontal" >
<ImageView
android:id="#+id/prevMonth"
android:layout_width="50dp"
android:layout_height="55dp"
android:src="#drawable/button_events_previous" >
</ImageView>
<TextView
android:id="#+id/currentMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.6"
android:gravity="center_vertical|center_horizontal"
android:text="Janauary"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#d458b1"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="#+id/nextMonth"
android:layout_width="50dp"
android:layout_height="55dp"
android:src="#drawable/button_events_next" />
</LinearLayout>
<TextView
android:id="#+id/direction_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:background="#DA81F5"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="PRESS RELEASES"
android:textColor="#FFFFFF"
android:textSize="13dip" />
<ListView
android:id="#+id/eventsList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="#+id/direction_label"
android:background="#ffffff" >
</ListView>
<TextView
android:id="#+id/direction_label1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#DA81F5"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="SPEECHES"
android:textColor="#FFFFFF"
android:textSize="13dip" />
<ListView
android:id="#+id/eventsList1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="#+id/direction_label1"
android:background="#ffffff" >
</ListView>
<TextView
android:id="#+id/empty_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
If I use this, nothing is shown :(
Asmi
EDIT : CODE FOR THE TWO LISTVIEWS:
{
arrayofWebData.add(cn);
listAdapter = new SelectArralAdapter(getActivity(),
arrayofWebData);
List_events.setAdapter(listAdapter);
}
For the Second ListView it is as follows :
if ((year == event_year) && (event_month == month))
{
arrayofWebDataPress.add(cn);
listAdapter_press = new SelectArralAdapter_Press(getActivity(),arrayofWebDataPress);
List_events_press.setAdapter(listAdapter_press);
i++;
}
Array Adapter for the two ListViews :
class SelectArralAdapter_Press extends ArrayAdapter<PressDB> {
private LayoutInflater inflater;
public SelectArralAdapter_Press(Context context,
ArrayList<PressDB> arrayofWebDataPress) {
super(context, R.layout.speech_list_item, R.id.event_title,
arrayofWebDataPress);
inflater = LayoutInflater.from(context);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder_Press holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.speech_list_item, null);
holder = new ViewHolder_Press(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder_Press) convertView.getTag();
}
holder.populateFrom(arrayofWebDataPress.get(position));
return (convertView);
}
}
class ViewHolder_Press{
public TextView event_name = null;
public TextView event_date = null;
public ViewHolder_Press(View row) {
event_name = (TextView) row.findViewById(R.id.event_title);
event_date = (TextView) row.findViewById(R.id.event_date_time);
}
void populateFrom(PressDB eventsMainDB) {
event_name.setText(eventsMainDB.press_name);
event_date.setText(eventsMainDB.press_date + " ");
}
}
For the second Adaper :
class SelectArralAdapter extends ArrayAdapter<SpeechDB> {
private LayoutInflater inflater;
public SelectArralAdapter(Context context,
ArrayList<SpeechDB> arrayofWebData) {
super(context, R.layout.speech_list_item, R.id.event_title,
arrayofWebData);
inflater = LayoutInflater.from(context);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.speech_list_item, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.populateFrom(arrayofWebData.get(position));
return (convertView);
}
}
class ViewHolder {
public TextView event_name = null;
public TextView event_date = null;
public ViewHolder(View row) {
event_name = (TextView) row.findViewById(R.id.event_title);
event_date = (TextView) row.findViewById(R.id.event_date_time);
}
void populateFrom(SpeechDB eventsMainDB) {
event_name.setText(eventsMainDB.speech_name);
event_date.setText(eventsMainDB.speech_date + " ");
}
}
Try this.
If you want to go with the xml design then you have to give the fix size, either by using the weight (this is most preferable) or by giving the fix size in dp.
<?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="#drawable/backrepeat"
android:weightSum="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_calendar_top"
android:orientation="horizontal" >
<ImageView
android:id="#+id/prevMonth"
android:layout_width="50dp"
android:layout_height="55dp"
android:src="#drawable/button_events_previous" >
</ImageView>
<TextView
android:id="#+id/currentMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.6"
android:gravity="center_vertical|center_horizontal"
android:text="Janauary"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#d458b1"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="#+id/nextMonth"
android:layout_width="50dp"
android:layout_height="55dp"
android:src="#drawable/button_events_next" />
</LinearLayout>
<TextView
android:id="#+id/direction_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:background="#DA81F5"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="PRESS RELEASES"
android:textColor="#FFFFFF"
android:textSize="13dip" />
<ListView
android:id="#+id/eventsList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:layout_below="#+id/direction_label"
android:background="#ffffff" >
</ListView>
<TextView
android:id="#+id/direction_label1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#DA81F5"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="SPEECHES"
android:textColor="#FFFFFF"
android:textSize="13dip" />
<ListView
android:id="#+id/eventsList1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:layout_below="#+id/direction_label1"
android:background="#ffffff" >
</ListView>
<TextView
android:id="#+id/empty_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
i am getting this screen at design time.
i have used like:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
// first linearlayout which is holding one textview and a listview
<LinearLayout
">
<TextView
/>
<ListView
android:id="#+id/failed_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"/>
</LinearLayout>
// second linearlayout which is holding one textview and a listview
<LinearLayout
">
<TextView
/>
<ListView
android:id="#+id/failed_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"/>
</LinearLayout>
// third linearlayout which is holding one textview and a listview
<LinearLayout
">
<TextView
/>
<ListView
android:id="#+id/failed_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"/>
</LinearLayout>
// and finally i have added a button in the parent linearlayout
<Button
/>
</LinearLayout>
</ScrollView>
you can try this.
Try out as below :
Here is the solution to more than one ListView within the same layout file. You can set the layout files as the below layout by providing the equal weights to each layout inside the LinearLayout.
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="#+id/list1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="#+id/list2"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
Java Code
public class MainActivity extends Activity {
private ListView lv1 = null;
private ListView lv2 = null;
private String s1[] = {"a", "b", "c", "d", "e", "f"};
private String s2[] = {"r", "s", "t", "u", "v", "w", "x"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv1 = (ListView) findViewById (R.id.list1);
lv2 = (ListView) findViewById (R.id.list2);
lv1.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, s1));
lv2.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, s2));
}
}
For more details you can refer the Link which have given the solution for same.
I hope it will help you.
Thanks.
You can take something like this.
<LinearLayout>
<ScrollView>
<LinearLayout>
{Your All code of controls}
</LinearLayout>
</ScrollView>
</LinearLayout>
OR uo can take <ScrollView> as parent tag..
You can do something like this. as per my Knowledge...
I solved the issue by using section headers and combining the two listviews into one listview and categorizing them by help of Section headers.

How to center align a textview below imageview as a title in a List view

I am not able to align a text below imageview in a listview. below is my code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="50dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/icon"
android:layout_alignParentBottom="true"
android:gravity="center"
android:singleLine="true"
android:layout_marginLeft="20dp"
android:textColor="#color/white"/>
</RelativeLayout>
and ListView is
<ListView android:id="#+id/grid_view"
android:layout_width="wrap_content"
android:layout_height="280sp"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp"
android:layout_toLeftOf="#+id/imgView"
android:scrollbars="none"
android:divider="#null"
android:gravity="center" >
</ListView>
java code to dynamically add text and image from array
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.gridview_layout, null);
holder = new ViewHolder();
holder.imageName = (TextView) convertView.findViewById(R.id.name);
holder.image = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.imageName.setText(name[position]);
holder.image.setImageResource(mThumbIds[position]);
return convertView;
}
not getting how to center text below imageview. please help me to solve this problem.
Simply use the layout_centerHorizontal attribute in your TextView:
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/icon"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:singleLine="true"
android:textColor="#color/white" />
In textview change
android:layout_width="wrap_content"
to
android:layout_width="match_parent"
You should use Linear layout to set orientation attribute. Set orientation to vertical for Linear layout and set imageview attribute android:layout_gravity="center"
Here is the complete code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
>
<ImageView
android:id="#+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/home" >
</ImageView>
<TextView
android:id="#+id/grid_item_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cardiology"
android:layout_gravity="center"
android:layout_marginTop="5px"
android:textSize="20sp" >
</TextView>
</LinearLayout>
hope it will help

android gridview fit the size in to screen

The gridview of my application has an image and a text below it for each grid.
I need to make sure that the complete list of grid fit in to the screen (no overflow at bottom).
Here is how i have defined my gridview
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:stretchMode="columnWidth"
android:layout_below="#+id/text1view"
android:gravity="center"
android:background="#drawable/home_bg"
/>
and each grid item is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/GridItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<ImageView android:id="#+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dip"
android:layout_margin="0dip"
>
</ImageView>
<TextView android:id="#+id/grid_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:padding="0dip"
android:gravity="center_horizontal"
android:layout_below="#+id/grid_item_image"
android:layout_alignParentBottom="true"
>
</TextView>
</LinearLayout>
I have tried several ways to set the grid view layout param, but i am not getting the right output. Please help me here. the gridview adapter code is
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.griditems, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView
.findViewById(R.id.grid_item_text);
Log.i(TAG, holder.text1.toString());
holder.image = (ImageView) convertView
.findViewById(R.id.grid_item_image);
// if it's not recycled, initialize some attributes
holder.image.setImageResource(gridItemIds[position]);
holder.text1.setText(gridTitles[position]);
int h = mContext.getResources().getDisplayMetrics().densityDpi;
convertView.setLayoutParams(new GridView.LayoutParams(h-50, h-20));
//holder.image.setScaleType(ImageView.ScaleType.CENTER_CROP);
//holder.image.setScaleType(ImageView.ScaleType.FIT_XY); ......
Try this:-
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center">
<ImageView android:id="#+id/imgIcon" android:src="#drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:text="TextView" android:id="#+id/txtDesc" android:layout_height="wrap_content" android:layout_width="wrap_content"></TextView>
</LinearLayout>
</LinearLayout>
gridview.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"
>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/mobGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>
try
android:layout_width="fill_parent"
android:layout_height="fill_parent"
for your GridView instead of wrap_content!

Categories

Resources