So I have a layout that contains a ListView...and underneath the ListView I have various other elements...my problem is that if the ListView gets a lot of elements, then the elements from the bottom disapear from the screen....How can i solve this?
My layout:
<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="wrap_content" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/header"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView android:id="#+id/name_header"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginLeft="10sp"
android:layout_marginTop="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:text="#string/product"
/>
<TextView android:id="#+id/quantity_header"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginTop="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/quantity"
android:gravity="center"
/>
<TextView android:id="#+id/total_price_header"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginTop="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/price"
android:gravity="center"
/>
</LinearLayout>
<View android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#FF0000"
android:layout_below="#+id/header"
/>
<ListView
android:id="#+id/listViewOrder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/line"
android:layout_marginTop="10sp"
android:layout_centerHorizontal="true" >
</ListView>
<View android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#FF0000"
android:layout_marginTop="10sp"
android:layout_below="#+id/listViewOrder"
/>
<TextView android:id="#+id/total_cost"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginTop="5sp"
android:layout_marginBottom="15sp"
android:layout_marginRight="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_below="#+id/line2"
/>
<RadioGroup android:id="#+id/radio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/total_cost">
<RadioButton android:id="#+id/radio_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_home"
android:layout_marginRight="20sp"
android:onClick="onRadioButtonClicked"
/>
<RadioButton android:id="#+id/radio_work"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_work"
android:onClick="onRadioButtonClicked"
/>
</RadioGroup>
</RelativeLayout>
Thanks
EDIT : The problem was in my approach..what I needed was a TableLayout...and the element outside to be a ScrollView
Put a layout_above on the listView. If you use layout_below on the lower view, it will size the listview first, then find a place ot put the thing below it, which will be off the screen. If you do a layout_above on the listView putting it above those elements, it will layout the elements below it first, then layout the listview above those, forcing it into the remaining space. Just remember to put the bottommost item aligned to the parent's bottom.
Related
I'm trying to create UI like the attached image. My xmal code below. There is one main issue that I"m running into. I understand that I can't embed a listview within a scrollview. The problem is, because of all the stuff on top of the listview, only a small portion of the listview is shown no matter what kind of height I give the parent linearlayout.
How can I layout my UI so that the listview will be visible and can be scrolled to with other UI elements on top of it? Any suggestion is apperciated.
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bkicon"
android:id="#+id/linearLayout1">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25dp"
android:minHeight="25dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/bkicon"
android:weightSum="4"
android:id="#+id/linearLayoutButtons">
<Button
android:text="Posts"
android:layout_width="50dp"
android:layout_height="100dp"
android:background="#drawable/mybuttonSelected"
android:layout_weight="1"
android:id="#+id/btngohomemb" />
<Button
android:text="Chat"
android:layout_width="50dp"
android:layout_height="100dp"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:id="#+id/btngohomemb" />
<Button
android:text="Business"
android:layout_width="50dp"
android:layout_height="100dp"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:id="#+id/btnMBRefresh" />
<Button
android:text="Resources"
android:layout_width="50dp"
android:layout_height="100dp"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:id="#+id/btnMBNewMessage" />
</LinearLayout>
<Button
android:text=""
android:gravity="left|center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#000000"
android:textStyle="bold"
android:background="#drawable/mybutton"
android:id="#+id/locHeader" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="left|center_vertical"
android:textColor="#000000"
android:id="#+id/locBody"
android:background="#FFFFFF" />
<TextView
android:text="\nWhat's on your mind?\n"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="left|center_vertical"
android:textColor="#ffffff"
android:id="#+id/lblWhatonyourmind"
android:background="#000000" />
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
<EditText
android:inputType="textMultiLine"
android:lines="8"
android:minLines="6"
android:gravity="top|left"
android:maxLines="10"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbars="vertical"
android:id="#+id/etNewPost" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/bkicon"
android:weightSum="3"
android:id="#+id/linearLayoutButtons">
<Button
android:text="Add Pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:id="#+id/btnPostPicture" />
<CheckBox
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/chbxRestrict" />
<Button
android:text="Post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:layout_weight="1"
android:id="#+id/btnPost" />
</LinearLayout>
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/lvPostedMsges" />
</LinearLayout>
This is happening because the heights of the elements above the Listview are taking the minimum space they need and thus leaving the small portion free for the list view, since linear layout stacks elements on after the other giving priority to the previous elements. So think about redesigning your page in a better way.
I am following tutorial from the book "Android Apps for Absolute Beginners 3rd Edition", and I am stuck with nested LinearLayout for android project in API 19 (4.4.2): Parent LinearLayout is horizontal and it is supposed to hold two child LinearLayout which are vertical and the end result should be like this:
But what I get is:
I tried several times, cross checked code in book, and explanations but I can't get it right.
Here is content of activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:background="#drawable/galaxyinfoscreen" >
<LinearLayout android:orientation="vertical" android:layout_margin="12dip"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#00000000">
<TextView android:text="#string/hello_world" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="48dip" android:textStyle="bold" />
<TextView android:text="#string/galaxy_name" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_solar" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_habit" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_colony" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_pop" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_fleet" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_ships" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_margin="33dip"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#00000000" >
<TextView android:text="#string/name_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView android:text="#string/solar_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/solar" />
<TextView android:text="#string/habit_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/habit"/>
<TextView android:text="#string/colony_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/colony" />
<TextView android:text="#string/pop_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/pop" />
<TextView android:text="#string/fleet_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/fleet" />
<TextView android:text="#string/ships_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/ships"/>
</LinearLayout>
</LinearLayout>
What could be missing from this file? What should I do to get desired result?
try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#drawable/galaxyinfoscreen"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="48dip"
android:text="#string/hello_world"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dip"
android:background="#00000000"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_name"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_solar"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_habit"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_colony"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_pop"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_fleet"
android:textColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/galaxy_ships"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dip"
android:background="#00000000"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/solar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/solar_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/habit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/habit_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/colony"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/colony_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/pop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pop_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/fleet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fleet_data"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/ships"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ships_data"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
"Glaxy Information Screen" TextView is inside first verical LinearLayout. As this text view is taking more space due to its margin and text length hence leaving less space for second linearlayout, resulting into wrap of text for sencond verical layout.
To solve the problem, add one more linear layout with orientation as horizontal as parent of both the vertical layout and add the "Glaxy Information Screen" text view as direct child of top parent.
you may need to make some adjustment to the margin values to aling the layouts.
In the second LinearLayout, the margin parameter is android:layout_marginTop="33dip
You forgot to put Top after margin.
;)
The second LinearLayout doesn't have enough width to accommodate the string and it gets wrapped. If you absolutely must use nested LinearLayout, you should use layout_weight instead of using width with wrapped content. In the example below, I have also moved the title out of the nested LinearLayout to another vertical one.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:background="#drawable/galaxyinfoscreen" >
<TextView android:text="#string/hello_world" android:textColor="#FFFFFF"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:textStyle="bold" />
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout android:orientation="vertical" android:layout_margin="12dip"
android:layout_width="0dp" android:layout_weight="3" android:layout_height="wrap_content"
android:background="#00000000">
<TextView android:text="#string/galaxy_name" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_solar" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_habit" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_colony" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_pop" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_fleet" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="#string/galaxy_ships" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_margin="12dip"
android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"
android:background="#00000000" >
<TextView android:text="#string/name_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView android:text="#string/solar_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/solar" />
<TextView android:text="#string/habit_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/habit"/>
<TextView android:text="#string/colony_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/colony" />
<TextView android:text="#string/pop_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/pop" />
<TextView android:text="#string/fleet_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/fleet" />
<TextView android:text="#string/ships_data" android:textColor="#FFFFFF"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/ships"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
With your current code i have two suggestions:
First:
android:singleLine="true"
add this tag to all your list views, so this will maintain symmetry in all your textView placement.
Secondly:
Keep a single Parent LinearLayout with orientation vertical, then have multiple LinearLayout with horizontal orientation and two TextView inside it.
I have problem with my TextView, when something is written in it. It narrows the right layout.
like here:
1 Without something is written: http://i.stack.imgur.com/zItJw.jpg
2.Without something is written in: http://i.stack.imgur.com/b5Nb4.jpg
My Layout Code:
1st bar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/dzialanie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="X razy Y" />
<TextView
android:id="#+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="=" />
<TextView
android:id="#+id/tylemabyc"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
2nd bar
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/czas"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
3rd bar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/wynik"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
How to block 1st TextView to not narrows others ?
You can use layout_weight property to tell android how much space each textView takes on the screen. If you want all of them to have the same space you can add the layout_weight of 1 for all of them.
You will also need to readjust your layout_width too. You will have to trade off for the layout_heght. For example if i want 4 textviews in a horizontal line holding equal space "Horizontally" i would do something like this:
<?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="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="This is verrry long text" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="maybe not" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="let us see" />
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ok" />
I have a particular LinearLayout where I have multiple components. I have a ScrollView in which I have another LinearLayout with a ImageView, two TextViews and Buttons. I also have a ListView at the very bottom of the page which shows comments. The problem is I want the ListView to show completely without any scrolling. The ListView scrolls giving a bad design. If I place the ListView outside the ScrollView, it does not show.
Here is my code:-
details.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" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="38.7dp"
android:background="#FF3C6FA6"
android:minHeight="25px"
android:minWidth="25px"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageBackBtn"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#FF3C6FA6"
android:fadingEdge="none"
android:src="#drawable/btnbackclickedxml" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Main vertical LinearLayout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/layoutList">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="Large Text"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<!-- Layout for Date, Likes, comments and views -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="98dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner" >
<TextView
android:id="#+id/txtPubDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#F8F8F8"
android:textSize="11sp"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<ImageButton
android:id="#+id/btnViews"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:background="#color/white"
android:src="#drawable/btnviewpressed" />
<TextView
android:id="#+id/txtViews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="view"
android:textColor="#FF3C6FA6"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageButton
android:id="#+id/btnComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_marginLeft="20dp"
android:src="#drawable/btncommentpressed"/>
<TextView
android:id="#+id/txtComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#FF3C6FA6"
android:text="view"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<ImageView
android:id="#+id/imgNewsImage"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/abc" />
<TextView
android:id="#+id/txtBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments" />
<Button
android:id="#+id/btnAddComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Comments" />
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/getdata"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:layout_gravity="bottom"
android:listSelector="#drawable/list_selector"
android:padding="5dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Take scrollview and Listview inside a one parent LinearLayout and assign weight for both , this may help you..
As per sending code in your problem you have used scroll view height with match_parent. To resolve this you have to set fixed height in your xml file or in your java file by get reference of your scroll view
I have arabic text, therefore I set gravity to right in order to start text from right side. Text starts from right now. But another issue is text starts to render from the top of the page. But I need to vertically center the text.
Although I tried several variations I couldnt make it vertically center.
Here is the sample of my xml file.
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="23dp"
android:gravity="right"
android:padding="#dimen/padding_maintextview"
android:text="#string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
</LinearLayout>
Problem is with above textview.
Here I have put whole xml file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/page1background"
android:paddingRight="#dimen/padding_large" >
<TextView
android:id="#+id/textView1"
android:layout_width="196dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:paddingTop="#dimen/padding_Title_Top"
android:text="#string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="5dp" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/linearLayout2"
android:layout_below="#id/linearLayout1"
android:layout_gravity="center"
android:padding="#dimen/padding_maintextview" >
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="23dp"
android:gravity="right"
android:padding="#dimen/padding_maintextview"
android:text="#string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<View
android:id="#+id/view2"
android:layout_width="fill_parent"
android:layout_height="100dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageButton
android:id="#+id/back_arrow"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginRight="45dp"
android:layout_weight=".5"
android:background="#drawable/backbut"
android:contentDescription="#string/Description"
android:onClick="onClickBtn"
android:src="#drawable/backarrowpress" />
<ImageButton
android:id="#+id/copyButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight=".5"
android:background="#drawable/copy"
android:contentDescription="#string/Description"
android:onClick="onClickBtn" />
</LinearLayout>
</RelativeLayout>
Can anybody show me where I have done the mistake? I think problem is clear. If not tell me in comments.
Herewith I have appended updated code after review your answers.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/page1background"
android:paddingRight="#dimen/padding_large" >
<TextView
android:id="#+id/textView1"
android:layout_width="196dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:paddingTop="#dimen/padding_Title_Top"
android:text="#string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="5dp" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/linearLayout2"
android:layout_below="#id/linearLayout1"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:padding="#dimen/padding_maintextview" >
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="23dp"
android:gravity="center_vertical|right"
android:padding="#dimen/padding_maintextview"
android:text="#string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<View
android:id="#+id/view2"
android:layout_width="fill_parent"
android:layout_height="100dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageButton
android:id="#+id/back_arrow"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginRight="45dp"
android:layout_weight=".5"
android:background="#drawable/backbut"
android:contentDescription="#string/Description"
android:onClick="onClickBtn"
android:src="#drawable/backarrowpress" />
<ImageButton
android:id="#+id/copyButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight=".5"
android:background="#drawable/copy"
android:contentDescription="#string/Description"
android:onClick="onClickBtn" />
</LinearLayout>
</RelativeLayout>
But I am in same situation. No text is vertically centered
Your TextView Attributes need to be something like,
<TextView ...
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|right" ../>
Now, Description why these need to be done,
android:layout_width="match_parent"
android:layout_height="match_parent"
Makes your TextView to match_parent or fill_parent if You don't want to be it like, match_parent you have to give some specified values to layout_height so it get space for vertical center gravity. android:layout_width="match_parent" necessary because it align your TextView in Right side so you can recognize respect to Parent Layout of TextView.
Now, its about android:gravity which makes the content of Your TextView alignment. android:layout_gravity makes alignment of TextView respected to its Parent Layout.
Update:
As below comment says use fill_parent instead of match_parent. (Problem in some device.)
The problem is the padding of the font on the textview. Just add to your textview:
android:includeFontPadding="false"
just use like this to make anything to center
android:layout_gravity="center"
android:gravity="center"
updated :
android:layout_gravity="center|right"
android:gravity="center|right"
Updated : Just remove MarginBottom from your textview.. Do like this.. for your textView
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center|right"
android:text="hello"
android:textSize="20dp" />
</LinearLayout>
Try to put android:gravity="center_vertical|right" inside parent LinearLayout else as you are inside RelativeLayout you can put android:layout_centerInParent="true" inside your scrollView.
In relative layout you need specify textview height:
android:layout_height="100dp"
Or specify lines attribute:
android:lines="3"