LinearLayout [Solved]

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

LinearLayout [Solved]

Postby michael1221988 » Fri Jan 08, 2010 4:55 am

I have a linearlayout with vertical orientation that has 3 TextViews in it. I would like the first textView to be always touching the top of the screen, while the 3rd one touches the bottom of the screen. The 2nd one would take up all the space in the middle. I have played with gravities and I can get either the whole thing attached to the top
Code: Select all
android:gravity="top"
or bottom
Code: Select all
android:gravity="bottom"
But I am unable to separate like I need to.

TIA
Last edited by michael1221988 on Sun Jan 10, 2010 6:13 pm, edited 1 time in total.
michael1221988
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jan 08, 2010 4:39 am

Top

Postby jwei512 » Fri Jan 08, 2010 7:12 am

Could you post the whole XML file? I can try to play around with it from there.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby michael1221988 » Fri Jan 08, 2010 7:15 am

Ok, So I lied. I simplified it to three textViews, but really it is more complicated, but you can see what I mean when you look at it. I want the middle ListView to take up the rest of the screen. Everything before the listView should float to the top and everything after the listView should sink to the bottom of the screen.

Code: Select all
<?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:gravity="bottom" android:orientation="vertical">
   <TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/current_song_header" android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:paddingTop="2dip"
      android:paddingBottom="2dip" android:paddingLeft="5dip" android:text="Current Song"
      style="?android:attr/listSeparatorTextViewStyle" />
   <LinearLayout android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:orientation="horizontal"
      android:baselineAligned="false" android:paddingLeft="11dip"
      android:layout_gravity="top" android:paddingTop="4dip"
      android:paddingBottom="8dip">
      <ImageView android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:layout_marginRight="4dip"
         android:src="@drawable/ic_mp_artist_playback" />
      <TextView android:id="@+id/artistname" android:textSize="18sp"
         android:singleLine="true" android:ellipsize="end" android:textStyle="bold"
         android:layout_gravity="center_vertical" android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
   </LinearLayout>
   <LinearLayout android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:orientation="horizontal"
      android:layout_gravity="top" android:baselineAligned="false"
      android:paddingLeft="11dip" android:paddingTop="4dip"
      android:paddingBottom="8dip">
      <ImageView android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:layout_marginRight="4dip"
         android:src="@drawable/ic_mp_album_playback" />
      <TextView android:id="@+id/albumname" android:textSize="14sp"
         android:singleLine="true" android:ellipsize="end"
         android:layout_gravity="center_vertical" android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
   </LinearLayout>
   <LinearLayout android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:orientation="horizontal"
      android:layout_gravity="top" android:baselineAligned="false"
      android:paddingLeft="11dip" android:paddingTop="0dip"
      android:paddingBottom="8dip">
      <ImageView android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:layout_marginRight="4dip"
         android:src="@drawable/ic_mp_song_playback" />
      <TextView android:id="@+id/trackname" android:textSize="14sp"
         android:singleLine="true" android:ellipsize="end"
         android:layout_gravity="center_vertical" android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
   </LinearLayout>
   <TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/upcoming_songs_header" android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:paddingTop="2dip"
      android:layout_gravity="center_vertical" android:paddingBottom="2dip"
      android:paddingLeft="5dip" android:text="Upcoming Songs"
      style="?android:attr/listSeparatorTextViewStyle" />
   <ListView android:id="@android:id/list" android:layout_width="fill_parent"
      android:layout_gravity="center_vertical" android:layout_height="wrap_content"
      android:drawSelectorOnTop="false" />
   <LinearLayout android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:background="#ff5a5a5a"
      android:paddingTop="1dip" android:paddingBottom="4dip"
      android:orientation="horizontal">
      <TextView android:id="@+id/currenttime"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textSize="14sp" android:textStyle="bold" android:shadowColor="#ff000000"
         android:shadowDx="0" android:shadowDy="0" android:shadowRadius="3"
         android:layout_gravity="bottom" android:layout_weight="1"
         android:layout_width="0dip" android:paddingLeft="5dip"
         android:layout_height="wrap_content" />
      <LinearLayout android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:orientation="horizontal"
         android:layout_gravity="bottom" android:layout_marginTop="1dip"
         android:layout_marginBottom="2dip" android:gravity="center">
         <org.mult.daap.RepeatingImageButton
            android:id="@+id/prev" style="@android:style/MediaButton.Previous" />
         <ImageButton android:id="@+id/pause" style="@android:style/MediaButton.Play" />
         <org.mult.daap.RepeatingImageButton
            android:id="@+id/next" style="@android:style/MediaButton.Next" />
      </LinearLayout>
      <TextView android:id="@+id/totaltime" android:textAppearance="?android:attr/textAppearanceMedium"
         android:textSize="14sp" android:textStyle="bold" android:shadowColor="#ff000000"
         android:shadowDx="0" android:shadowDy="0" android:shadowRadius="3"
         android:gravity="right" android:paddingRight="5dip"
         android:layout_gravity="bottom" android:layout_weight="1"
         android:layout_width="0dip" android:layout_height="wrap_content" />
   </LinearLayout>
   <SeekBar android:id="@android:id/progress" android:background="#ff5a5a5a"
      style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent"
      android:layout_height="36dip" android:paddingLeft="8dip"
      android:layout_gravity="bottom" android:paddingRight="8dip"
      android:paddingBottom="4dip" />
</LinearLayout>
michael1221988
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jan 08, 2010 4:39 am

Postby michael1221988 » Sun Jan 10, 2010 6:13 pm

I figured out what I needed. Android provides something called weight. If you give a weight to your object in the xml android will spread the object until it fills the screen. The weights must add up to 1. For my case. I just attached a weight of 1 to the listview and it took up the remaining part of the screen.
michael1221988
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jan 08, 2010 4:39 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests