I have this layout for my row in a listview... last image is not displayed... why?
<?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="70dip"
android:background="#android:color/black">
<ImageView
android:id="#+id/img"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:layout_marginLeft="5dip"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/title"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginLeft="10dip"
android:layout_marginTop="1dip"/>
<TextView android:id="#+id/description"
android:typeface="sans"
android:textSize="12sp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:layout_weight="0"
android:layout_marginLeft="10dip"/>
<TextView android:id="#+id/variable"
android:textSize="12sp"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lines="1"
android:ellipsize="end"
android:layout_weight="0"
android:layout_marginLeft="10dip"/>
</LinearLayout>
<ImageView
android:id="#+id/img"
android:src="#drawable/disclosure"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:layout_marginLeft="5dip"/>
</LinearLayout>
Thanks in advance,
regards
EDIT: Try using a relativelayout so you don't have to have a linearlayout in the middle. I also have a three columnish thing going on so it should be similar for you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id ="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="62dp"
android:cacheColorHint="#ff000000"
android:background="#color/white"
android:clickable="true"
>
<ImageView
android:layout_height="60dp"
android:layout_width="60dp"
android:id="#+id/thumbnail"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
android:scaleType="fitXY"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_toRightOf="#id/thumbnail"
android:textSize="13dp"
android:textStyle="bold"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_alignTop = "#id/thumbnail"/>
<TextView
android:id="#+id/merchant"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_toRightOf="#id/thumbnail"
android:textSize="12dp"
android:textStyle="normal"
android:textColor="#000000"
android:ellipsize="end"
android:focusable="true"
android:lines="1"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"/>
<TextView
android:id="#+id/distance"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/merchant"
android:layout_toRightOf="#id/priceButton"
android:textColor="#color/black"
/>
<Button
android:id="#+id/priceButton"
android:layout_height="60dp"
android:layout_width="70dp"
android:textColor="#color/white"
android:textSize="14dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
/>
</RelativeLayout>
With no screenshot I would imagine you just have too much data on the screen , use a scrollview to allow the user to scroll.
Also why is your root layout's height limited to 70? Why dont you use fill_parent or match_parent
Related
I have tried LinearLayout inside which I put several textview. I completely use weights for each and every view. Problem arises when data becomes too much in lenght and textview not shows it completely. I also tried tabletlayout but that thing also not works beacuse ultimately tablelayout is inside linear layout having weight,so it doesn't grows beyond a certain limit. I want to know how can I make a activity scrollable with showing all data while using weights.
Use Scrollview in xml Layout of your activity.
Example:
XML code for your activity:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:fillViewport="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/image" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="KNOW MORE" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/description"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
You can Use Scroll View With Linear Layout as well as With Relative layout.
You Can try this code, Just Copy and paste in XML File.
U'll Get Your ans :)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#android:color/black"
>
<TextView
android:id="#+id/TV_Welcome"
android:text="ADD YOUR VEHICLE"
android:layout_marginLeft="70dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:textColor="#color/menu_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"/>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_below="#+id/TV_Welcome"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_BlockNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Block No:"
android:textColor="#color/version_color"
android:layout_marginLeft="10dp"
android:textSize="15dp"
android:layout_alignParentLeft="true"
android:gravity="left"
/>
<Spinner
android:id="#+id/Spinner_BlockNo"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/TV_BlockNo"
android:background="#558cff"
android:layout_width="300dp"
android:layout_height="wrap_content">
</Spinner>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_margin="10dp"
android:layout_below="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TV_FlatNo"
android:text="Flat NO:"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:textColor="#color/version_color"
/>
<Spinner
android:id="#+id/Spinner_FlatNo"
android:layout_marginLeft="42dp"
android:layout_toRightOf="#+id/TV_FlatNo"
android:background="#558cff"
android:layout_width="300dp"
android:layout_height="wrap_content"></Spinner>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout03"
android:layout_below="#+id/RelativeLayout02"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_VehicleNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vehicle No:"
android:textColor="#color/version_color"
android:layout_marginLeft="10dp"
android:textSize="15dp"
android:layout_alignParentLeft="true"
android:gravity="left"
/>
<EditText
android:id="#+id/ET_VehicleNo"
android:layout_marginLeft="20dp"
android:hint="Enter Vehicle No"
android:textColorHint="#color/menu_glow"
android:textSize="20dp"
android:layout_toRightOf="#+id/TV_VehicleNo"
android:textColor="#558cff"
android:layout_width="400dp"
android:layout_height="wrap_content"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout04"
android:layout_margin="10dp"
android:layout_below="#+id/RelativeLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TV_VehicleType"
android:text="Vehicle Type:"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:textColor="#color/version_color"
/>
<Spinner
android:id="#+id/Spinner_VehicleType"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/TV_VehicleType"
android:background="#558cff"
android:layout_width="300dp"
android:layout_height="wrap_content">
</Spinner>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout05"
android:layout_margin="10dp"
android:layout_below="#id/RelativeLayout04"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_OwnerName"
android:text="Owner Name:"
android:textSize="15dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left">
</TextView>
<EditText
android:id="#+id/ET_OwnerName"
android:hint="Enter Owner Name"
android:textColorHint="#color/menu_glow"
android:inputType="textPersonName"
android:layout_marginLeft="20dp"
android:textSize="20dp"
android:layout_toRightOf="#id/TV_OwnerName"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="400dp">
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout06"
android:layout_margin="10dp"
android:layout_below="#id/RelativeLayout05"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_MobileNo"
android:text="Mobile No:"
android:textSize="15dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left">
</TextView>
<EditText
android:id="#+id/ET_MobileNo"
android:layout_marginLeft="40dp"
android:hint="Enter 10 digit"
android:textColorHint="#color/menu_glow"
android:inputType="phone"
android:textSize="20dp"
android:layout_toRightOf="#id/TV_MobileNo"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="200dp"
>
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout07"
android:layout_margin="10dp"
android:layout_below="#id/RelativeLayout06"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_TelNo"
android:text="Telephone No:"
android:textSize="15dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
<EditText
android:id="#+id/ET_TelNo"
android:layout_marginLeft="20dp"
android:hint="Enter Telephone No"
android:textColorHint="#color/menu_glow"
android:inputType="number"
android:textSize="17dp"
android:layout_toRightOf="#id/TV_TelNo"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout08"
android:layout_margin="0dp"
android:layout_below="#id/RelativeLayout07"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_Example"
android:text="(Example:0141-2206923)"
android:layout_marginLeft="120dp"
android:textSize="10dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
</RelativeLayout>
<ImageView
android:id="#+id/ImageView_Submit"
android:layout_marginTop="5dp"
android:layout_marginLeft="100dp"
android:layout_centerInParent="true"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/submit"
android:layout_below="#id/RelativeLayout08"
android:onClick="doSubmit"></ImageView>
</RelativeLayout>
</ScrollView>
You can make your activity scrollable using ScrollView.
Its very simple and effective to use.Just copy code of ScrollView from below and paste it in your layout xml file.
You can use this ScrollView with Linear as well as Relative Layout also.
Just need to remember one thing,ScrollView can have only one child widget.If you want more Children then wrap them into one container.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/xyz.png"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView1"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView2"/>
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView3"/>
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView4"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Demo" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I'm trying to make a layout xml to fit like the layout below:
This layout goes in a row of listview.
The problem is: The thumbnail need to fit the middle of the row horizontally, and the star too, this is my layout xml with best approach:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:id="#+id/thumbnail"
android:src="#drawable/ic_thumbnail"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/favoriteVendor"
android:layout_toRightOf="#+id/thumbnail">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNameNameName"
android:singleLine="true"
android:ellipsize="marquee"
android:id="#+id/vendorName"
android:textSize="20dp" />
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pin_point_rating"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNaNameNameNameNameNameNameNamemeNameName"
android:id="#+id/vendorAddress"
android:singleLine="true"
android:ellipsize="marquee"/>
</LinearLayout>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/favoriteVendor"
android:adjustViewBounds="true"
android:textOn=""
android:textOff=""
android:background="#drawable/star"
android:scaleType="centerCrop"
android:layout_margin="8dp" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
</RelativeLayout>
Does anyone know how to do it? I've tried lot of combinations
I guess a much better way to do this (This is just a layout, use padding as you wish)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_toRightOf="#+id/photo"
android:layout_toLeftOf="#+id/tb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"/>
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pin_point_rating"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"/>
</LinearLayout>
<ToggleButton
android:id="#+id/tb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Try this way,hope this will help you to solve your problem,i have using LinearLayout to achieved your requirement.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/thumbnail"
android:src="#drawable/ic_thumbnail"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNameNameName"
android:singleLine="true"
android:ellipsize="marquee"
android:id="#+id/vendorName"
android:textSize="20dp" />
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pin_point_rating"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNaNameNameNameNameNameNameNamemeNameName"
android:id="#+id/vendorAddress"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_marginTop="5dp"/>
</LinearLayout>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/favoriteVendor"
android:adjustViewBounds="true"
android:background="#drawable/star"
android:scaleType="centerCrop"
android:layout_marginLeft="5dp"/>
</LinearLayout>
I have an ImageView (android:id="#+id/unreadmail) which i want to show on extreme left of ListItem as shown in image. But it is not aligning properly. Any idea if i am missing anything ?
<LinearLayout
android:id="#+id/Text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/unreademail"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/emailsubject"
android:layout_centerVertical="true"
android:background="#8A6175"
android:visibility="invisible" />
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="20dip"
android:textColor="#313132"
android:textSize="12sp" />
Use this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="ObsoleteLayoutParam,ContentDescription,UselessLeaf,UselessParent" >
<LinearLayout
android:id="#+id/Text"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/unreademail"
android:layout_width="15dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_launcher"
android:visibility="visible" />
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="right"
android:layout_gravity="right"
android:orientation="horizontal" >
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp"
android:text="Date"
android:textColor="#000"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I think you should be using a relative layout at the top level (possibly not included in your code).
You cannot use 'to the left of' when the elements are at different levels in the heirarchy.
Thus I would start with your little icon left aligned to the parent and put the edit box (in the same relative view) 'to the right of' the icon.
This is the code sample for you there is no need to write the weight property if add the screenshot or the supported image how exactly you want then i can give you proper answer
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/unreademail"
android:layout_marginLeft="10dip"
android:orientation="vertical">
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/unreademail"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#8A6175"
android:visibility="invisible" />
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="20dip"
android:textColor="#313132"
android:textSize="12sp" />
</RelativeLayout>
This layout is used as the layout for items in a listView. I had a really simple layout, and everything was working fine, but now i have changed it a little and it is crashing my app when it tries to load.. Not sure what im doing wrong
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
When you use android:layout_weight put layout_width="0dip"
Working code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView
android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|bottom"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|top"
android:textColor="#545454"
android:textSize="16dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
You need to add android:layout_width=".." and android:layout_height=".."to all the views:
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
every element you gave android_layout_weight you didn't give a width. If you gave this weight so the element takes a certain space you should give the layout
android:layout_width="0"
so it takes the weight as width
height and width are required tags for every element
you have missed some layout width and layout height attributes.
i have added in the all items.
Please use the below code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_height="fill_parent"
android:weightSum="2"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:layout_width="fill_parent"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
I don't know exactly what you want to achieve here by this layout but there are few mistake in your xml.
At various places width and height are missing. Consider adding those.
You are adding LinearLayout as parent tag but using RelativeLayout Tags like
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
do consider removing those.
Use properly combination of android:layout_weight="" and android:layout_height="" , android:layout_width=""
Comment if any clarification or help required
I need to have multiple textviews within a scrollview. I am using a relative layout as a container to all these textviews.
The layout looks fine in portrait orientation, but when in landscape orientation, the textview at the top of the relative layout within the scrollview (tvEx) is not visible. This is only when I test in the emulator for devices that have a small screen. Apart from this minor problem, the layout works perfectly well. Although, this seems to be a minor issue, somehow I am not able to get around it. Kindly help.
The layout file is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#drawable/background" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header" >
<Button
android:id="#+id/btBack"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/back"
android:visibility="invisible" />
<TextView
android:id="#+id/tvBanner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBaseline="#+id/btBack"
android:layout_alignBottom="#+id/btBack"
android:layout_alignParentLeft="true"
android:gravity="fill"
android:text="Practice Exam"
android:textColor="#android:color/white"
android:textSize="20sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/footer"
android:orientation="horizontal" >
<Button
android:id="#+id/btHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/home" />
</RelativeLayout>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/RelativeLayout1"
android:layout_below="#+id/Header"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center" >
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/tvEx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentTop="true"
android:text="Congratulations!!"
android:textColor="#android:color/white"
android:textSize="24sp"/>
<TextView
android:id="#+id/tvRes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvEx"
android:gravity="center"
android:text="You passed"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvLuck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvRes"
android:layout_margin="10dp"
android:gravity="center"
android:text="Great going"
android:textColor="#android:color/white"
android:textSize="18sp" />
<LinearLayout
android:id="#+id/lins"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_below="#+id/tvLuck"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE:"
android:textColor="#android:color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/tvScoreNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tvScore"
android:layout_alignBaseline="#+id/tvScore"
android:textColor="#android:color/white"
android:textSize="28sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/tvCorr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lins"
android:layout_margin="10dp"
android:layout_marginTop="47dp"
android:gravity="center_horizontal"
android:text="Correct Answers:"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvIncorr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvCorr"
android:gravity="center_horizontal"
android:text="Incorrect Answers:"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvtot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvIncorr"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Total Questions:"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I had a similar problem in a ScrollView. Try changing android:gravity="center" to android:gravity="center_horizontal" or removing it completely. Similar to ScrollView hides.