I am trying to line up the text and images next to each other in a perfect line but cant quite get it center.
As you see with the image it's almost center next to each other but not perfectly what am I missing
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/textView1"
android:textSize="14dp"
android:textStyle="bold"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/textView1"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_ls"
/>
<TextView
android:id="#+id/textView2"
android:textSize="14dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:layout_toRightOf="#+id/imageView1"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/textView2"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_ls"
/>
<TextView
android:id="#+id/textView3"
android:layout_toRightOf="#+id/imageView2"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:textSize="14dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp">
<TextView
android:id="#+id/textView1"
android:textSize="14dp"
android:textStyle="bold"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/image_ls" />
<TextView
android:id="#+id/textView2"
android:textSize="14dp"
android:layout_marginLeft="5dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView" />
<ImageView
android:id="#+id/imageView2"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/image_ls" />
<TextView
android:id="#+id/textView3"
android:textSize="14dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView" />
</LinearLayout>
Try This Code:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/textView1"
android:textSize="14dp"
android:textStyle="bold"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/textView1"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_ls"
/>
<TextView
android:id="#+id/textView2"
android:textSize="14dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:layout_toRightOf="#+id/imageView1"
android:layout_centerVertical="true"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/textView2"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_ls"
/>
<TextView
android:id="#+id/textView3"
android:layout_toRightOf="#+id/imageView2"
android:layout_centerVertical="true"
android:gravity="center_vertical|right"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:textSize="14dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
/>
</RelativeLayout>
<?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:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
Try this:
Use LinearLayout to fix android widgets in vertical or horizontal.
<?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:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/ic_launcher" />
Related
This is the my current listivew:
My problem is i can't display my last item in the list. It's like getting cut by my phone.
Here is the xml code:
<?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"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:background="#drawable/dfcomment3"
android:layout_weight="0.07">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
As much as possible i want to stick with the listview because i'm not familiar with the recyclerview. if theres any way to fix this, i would be glad.
Check the image for the reference of my problem.
There's actually 4 items in the list and i can only view 2 items.
Firstly there is problem with your XML as when you use weightsum and layout_weight then you need not give dimensions in height or width.
This must be your XML.
Also I checked your XML there is some problem in you XML attributes too. Like you used "android:layout_below="#+id/id"" but in your xml there is no "id"
<?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"
android:weightSum="100">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/dfcomment3"
android:layout_weight="70">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="30"
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
Add your java code if you are not getting 4 values into your ListView
Change you xml to :
<?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"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_weight="0.07"--> Delete this
>
....
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1" -> Add this
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
i have problem that when i am using a text view
the text from the list view come over my toolbar
i don't know what to do , please help me
because i want to use later to toolbar for make
search filter .
thanks to all the helpers if you need me to add my style file or something please let me know !
activity xml :
<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:orientation="vertical"
tools:context=".MainActivity" >
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
custom list xml
<?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="wrap_content"
android:orientation="horizontal"
android:background="#dee2e2">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:layout_marginLeft="10dp">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="TextView" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView3"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView4"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView5"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView6"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView7"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView8"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView9"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView10"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView11"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView12"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView13"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView14"
android:layout_marginLeft="10dp" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/edit_icon"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageView
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/imageView"
android:src="#drawable/edit_icon"
android:layout_marginBottom="10dp"
android:layout_margin="5dp" />
<ImageView
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/imageView2"
android:src="#drawable/edit_icon"
android:layout_marginBottom="10dp"
android:layout_margin="5dp" />
<ImageView
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/imageView3"
android:src="#drawable/edit_icon"
android:layout_marginBottom="20dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp" />
<ImageView
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/imageView4"
android:src="#drawable/edit_icon"
android:layout_marginBottom="10dp"
android:layout_margin="5dp" />
<ImageView
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/imageView5"
android:src="#drawable/edit_icon"
android:layout_marginBottom="10dp"
android:layout_margin="5dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am displaying text and images in a list format next to each other but I can't get them to line up perfectly center next to each other in a straight line what am I missing
Here is my layout code below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold"
android:layout_gravity="center|right"
android:gravity="center|right"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textView1"
android:layout_gravity="center|right"
android:gravity="center|right"
android:src="#drawable/image_ls"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:text="TextView"
android:textSize="14dp"
android:layout_toRightOf="#+id/imageView1"
android:textStyle="bold"
android:gravity="center|right"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_gravity="center|right"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textView2"
android:src="#drawable/image_ls"
android:gravity="center|right"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
/>
</RelativeLayout>
This does work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="5dp"
android:gravity="center_vertical|center_horizontal"
android:background="#color/gray_dark">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="TextView"
android:textSize="14dp"
android:textStyle="bold"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_marginLeft="5dp"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/textView1"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:src="#drawable/image_ls"
android:layout_marginLeft="5dp"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|right"
android:text="TextView"
android:textSize="14dp"
android:layout_toRightOf="#+id/imageView1"
android:textStyle="bold"
android:gravity="center_vertical|right"
android:layout_marginLeft="5dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/textView2"
android:src="#drawable/image_ls"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_marginLeft="5dp"
/>
</RelativeLayout>
i would prefer a linear layout over relative for this situation with this simple layout design, it is easier and straight forward you just need to use:
android:layout_gravity="center_vertical"
and play around with weights if any other size restriction is required.
here is the solution hope its what you need:
<?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:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/ic_launcher"
android:layout_marginTop="10dp"
/>
</LinearLayout>
</LinearLayout>
I have a scrollable Android layout which is defined by the following code:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/horizontal_rule_in_registration" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="23dp" >
<View
android:id="#+id/advertising_image"
android:layout_width="306dp"
android:layout_height="175dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/inno_luck_sample_advertisement_picture" />
<TextView
android:id="#+id/advertiser_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertising_image"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/business_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertiser_name_text"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/ad_description_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/business_text"
android:layout_marginTop="12dp"
android:maxLines="2"
android:singleLine="false"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<TextView
android:id="#+id/advertiser_contact_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/ad_description_text"
android:layout_marginTop="12dp"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<TextView
android:id="#+id/advertiser_address_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertiser_contact_text"
android:layout_marginTop="12dp"
android:maxLines="2"
android:singleLine="false"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<TextView
android:id="#+id/advertiser_website_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertiser_address_text"
android:layout_marginTop="12dp"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<Button
android:id="#+id/next_ok_btn"
android:layout_width="190dp"
android:layout_height="29dp"
android:layout_below="#id/advertiser_website_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:background="#drawable/next_button_bg"
android:gravity="center"
android:text="#string/next"
android:textColor="#color/next_clr"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
However as the picture below shows, this does not show the bottom most part of the layout.
How can I overcome this problem?
Try to give padding in your Relative layout
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="23dp"
android:paddingBottom="10dp">
try this code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="#id/horizontal_rule_in_registration" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="23dp" >
<View
android:id="#+id/advertising_image"
android:layout_width="306dp"
android:layout_height="175dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/inno_luck_sample_advertisement_picture" />
<TextView
android:id="#+id/advertiser_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertising_image"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/business_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertiser_name_text"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/ad_description_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/business_text"
android:layout_marginTop="12dp"
android:maxLines="2"
android:singleLine="false"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<TextView
android:id="#+id/advertiser_contact_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/ad_description_text"
android:layout_marginTop="12dp"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<TextView
android:id="#+id/advertiser_address_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertiser_contact_text"
android:layout_marginTop="12dp"
android:maxLines="2"
android:singleLine="false"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<TextView
android:id="#+id/advertiser_website_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/advertiser_address_text"
android:layout_marginTop="12dp"
android:textColor="#color/register_text_clr"
android:textSize="18sp" />
<Button
android:id="#+id/next_ok_btn"
android:layout_width="190dp"
android:layout_height="29dp"
android:layout_below="#id/advertiser_website_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:background="#drawable/next_button_bg"
android:gravity="center"
android:text="#string/next"
android:textColor="#color/next_clr"
android:textSize="18sp" />
</RelativeLayout>
hope this helps
try this for your ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
....
In my app am using customized listed view with text view and Buttons.The screen size is 4.65" 720p(720X1280 : xhdpi),device take this resolution from layout-large folder.when i run it on device.the list view item and header display not fit to the screen like image shown below,some empty space in the end of row.Its not able to fit to the screen.Can any one know please help me to solve this issue.
Header XML Coding
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/search_lay"
android:layout_marginTop="1dp"
android:background="#e8e8e8" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="32dp"
android:text="Item(s)"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="48dp"
android:layout_toRightOf="#+id/textView1"
android:text="Price(Rs.)"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#+id/textView3"
android:text="Qty"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="28dp"
android:layout_toRightOf="#+id/textView2"
android:text="Total(Rs.)"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="3dp"
android:text="Fav"
android:textColor="#dd1713"
android:textSize="13sp" />
</RelativeLayout>
Customized List-view XML Coding
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ffffff" >
<TextView
android:id="#+id/orderlist_product_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<RelativeLayout
android:layout_width="30dp"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/fav_img"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/fav_order_list_btn" />
<Button
android:id="#+id/special_inst_btn"
android:layout_width="25dp"
android:layout_height="18dp"
android:layout_below="#+id/fav_img"
android:layout_centerHorizontal="true"
android:background="#drawable/special_inst_btn_in_orderlist"
android:gravity="center"
android:text="+"
android:textColor="#ffffff"
android:textSize="14sp" />
</RelativeLayout>
<TextView
android:id="#+id/order_list_itemname"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="1dp"
android:text="Item name"
android:textColor="#000000"
android:textSize="12sp"
android:typeface="serif" />
<RelativeLayout
android:layout_width="34dp"
android:layout_height="match_parent"
android:layout_marginLeft="2dp" >
<TextView
android:id="#+id/orderlist_offer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:gravity="center"
android:textColor="#298616"
android:textSize="10sp" />
<TextView
android:id="#+id/orderlist_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:text="200.00"
android:textColor="#000000"
android:textSize="10sp"
android:typeface="serif" />
</RelativeLayout>
<Button
android:id="#+id/orderlist_minus"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="1dp"
android:background="#drawable/sub_button_click" />
<EditText
android:id="#+id/order_list_quantity"
android:layout_width="27dp"
android:layout_height="25dp"
android:layout_marginTop="13dp"
android:background="#drawable/et_bg"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:inputType="number"
android:textColor="#000000"
android:textSize="12dp"
android:typeface="serif" >
<requestFocus />
</EditText>
<Button
android:id="#+id/orderlist_plus"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginTop="1dp"
android:background="#drawable/plus_btn_click" />
<TextView
android:id="#+id/orderlist_total"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="13dp"
android:gravity="right"
android:text="1000.00"
android:textColor="#000000"
android:textSize="11sp"
android:typeface="serif" />
<Button
android:id="#+id/orderlist_delete"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:layout_marginTop="1dp"
android:background="#drawable/order_list_delete" />
</LinearLayout>
</RelativeLayout>
i m giving u a demo.this layout will work on all size layout,this will definitely help u #Yugesh.
weight works percentage-wise on all screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".30"
android:gravity="center_horizontal" >
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/image1"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".30"
android:text="30%" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:text="20%" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:text="20%" />
</LinearLayout>
</RelativeLayout>
further more,if there is any query,then please ask...