I cannot put TextView on the right side of ImageView - android

I'm kind of new in Android App develop, there is my problem, I created a scrollview, inside scrollview I have LinearLayout. The problem is in the LinearLayout I cannot put the textview beside to the ImageView, really stuck here.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_item_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.ItemDetail">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv_bookTitle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="Title"
android:textStyle="bold"
android:textSize="20dp"/>
<TextView
android:id="#+id/tv_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="ISBN"/>
<ImageView
android:id="#+id/imageView_book"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/tv_bookPrice"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="$0.00"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_bookInfo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:text="This is bookInfo"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<ImageView
android:id="#+id/imageView_seller"
android:layout_width="80dp"
android:layout_alignParentLeft="true"
android:layout_margin="8dp"
android:layout_height="80dp" />
<TextView
android:id="#+id/tv_sellerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView_seller"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView_seller"
android:layout_toRightOf="#+id/imageView_seller"
android:layout_gravity="center_horizontal"
android:textSize="20dp"
android:text="Seller INFO"/>
</LinearLayout>
</ScrollView>
This is what happened

This XML Code might help you...
I have set imageView_seller at leftside of tv_sellerInfo
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_item_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_bookTitle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="Title"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="ISBN"/>
<ImageView
android:id="#+id/imageView_book"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/tv_bookPrice"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="$0.00"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_bookInfo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:text="This is bookInfo"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView_seller"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center_vertical"
android:layout_margin="8dp"/>
<TextView
android:id="#+id/tv_sellerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Seller INFO"
android:textSize="20dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

This happens because the orientation of your LinearLayout is vertical (one view below the other), try to change to horizontal or change of LinearLayout to RelativeLayout and add the constraints that you want.

add a linearlayout where you want to put textview right of image view. set the orientation of this linearlayout is hrizontal then put imageview and then textview in this linearlayout

do this -
android:orientation="horizontal"
like this-
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_item_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:orientation="horizontal"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.ItemDetail">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv_bookTitle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="Title"
android:textStyle="bold"
android:textSize="20dp"/>
<TextView
android:id="#+id/tv_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="ISBN"/>
<ImageView
android:id="#+id/imageView_book"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/tv_bookPrice"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="$0.00"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_bookInfo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:text="This is bookInfo"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<ImageView
android:id="#+id/imageView_seller"
android:layout_width="80dp"
android:layout_alignParentLeft="true"
android:layout_margin="8dp"
android:layout_height="80dp" />
<TextView
android:id="#+id/tv_sellerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView_seller"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView_seller"
android:layout_toRightOf="#+id/imageView_seller"
android:layout_gravity="center_horizontal"
android:textSize="20dp"
android:text="Seller INFO"/>
</LinearLayout>
</ScrollView>

Related

How to Align an ImageView to the right side?

I want to set an imageview to the right side inside the cardview but aligning is not working... please suggest me
Layout
<FrameLayout
android:id="#+id/framelayout"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lin1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginTop="15dp"
android:id="#+id/casardviewvisit">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#482048"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/omg"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#fff"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:text="Add Order"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sent"
android:layout_gravity="right"
android:id="#+id/imageButtsdon" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</framelayout>
Like this way i am trying but it is not working and i don't know why this is not working
Please use this code to set Imageview to right side inside CardView, just using the Relative layout.
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/casardviewvisit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginTop="15dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#482048">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Add Order"
android:textColor="#fff"
android:textSize="20dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/imageButtsdon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:src="#drawable/beautiful" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Use RelativeLayout instead of LinearLayout
and add
android:layout_alignParentRight="true"
to the ImageView
thats all !!
Make your TextView stretched by doing
android:layout_width="0dp"
android:layout_weight="1"
You can use following code.
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginTop="15dp"
android:id="#+id/casardviewvisit">
<LinearLayout
android:weightSum="1"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#482048"
android:orientation="horizontal">
<ImageView
android:layout_weight=".2"
android:layout_width="0dp"
android:layout_height="50dp"
android:src="#drawable/test"/>
<TextView
android:layout_weight=".5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#fff"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:text="Add Order"/>
<ImageView
android:layout_weight=".2"
android:layout_width="0dp"
android:layout_height="50dp"
android:src="#drawable/test"
android:layout_gravity="right"
android:id="#+id/imageButtsdon" />
</LinearLayout>
</android.support.v7.widget.CardView>
You can copy and paste it your xml file
Just use simple gravity for your image view.
<FrameLayout
android:id="#+id/framelayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lin1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginTop="15dp"
android:id="#+id/casardviewvisit">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#482048"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#fff"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:text="Add Order"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sent"
android:layout_gravity="right"
android:id="#+id/imageButtsdon" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_gravity="end"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:src="#drawable/omg"/>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Please check the following xml.
<FrameLayout
android:id="#+id/framelayout"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lin1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginTop="15dp"
android:id="#+id/casardviewvisit">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#482048"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#482048"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#fff"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:text="Add Order"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sent"
android:layout_gravity="right"
android:id="#+id/imageButtsdon" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/omg"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</framelayout>
Inside the Cardview, the container LinearLayout just give Weightsum of 1 and give both the Imageviews a weight of .25 and textview a weight of .5 as shown below
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/casardviewvisit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="05dp"
android:layout_marginTop="15dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#482048"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:src="#drawable/omg" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_weight=".5"
android:text="Add Order"
android:textColor="#fff"
android:textSize="20dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/imageButtsdon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight=".2"
android:src="#drawable/sent" />
</LinearLayout>
</android.support.v7.widget.CardView>

how i can set my items to full screen of all device

how i can set my items to full screen of all device,
i have RecyclerView and CardView for horizontal and vertical listview
singleitems.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:cardCornerRadius="5dp"
app:cardUseCompatPadding="true">
<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"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<TextView
android:id="#+id/txt_az"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<TextView
android:id="#+id/txt_be"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<TextView
android:id="#+id/txt_tripCondition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<TextView
android:id="#+id/txt_tripCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<TextView
android:id="#+id/txt_tripDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
main_items.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="wrap_content"
android:background="?android:selectableItemBackground"
android:orientation="vertical"
android:padding="5dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_list"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_vertical"
android:gravity="right"
android:orientation="horizontal" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:background="#android:color/holo_green_dark">
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#+id/btnMore"
android:text="Sample title"
android:textColor="#android:color/white"
android:textSize="18sp" />
<Button
android:id="#+id/btnMore"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="More" />
</RelativeLayout>
and i use like this in my activity_main.xml :
<FrameLayout 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"
tools:context="com.software.mahoo.operator.Activityes.Act_Request">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:gravity="right"/>
with this code my item is like this picture :
i want fit to all device fullscreen like this picture :
items is horizontal , and with swipe to right item change scroll to next item .
how i can do this ?

Android XML code : how to place an image left of Textview?

In my Android Application i have 2 textviews and 1 image to e displayed on the listview. While i used my imageview it is going to the new line..
I want one textview and imageview on the same line. Every time i place the imageview the whole alignment is changing ..
my XML code is
<?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"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="left"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/album1" />
<TextView
android:layout_toRightOf="#id/icon"
android:id="#+id/textViewSongName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#android:color/white"
android:textSize="22dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textViewArtist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_weight="1"
android:textColor="#android:color/white"
android:textSize="15dp" />
<TextView
android:id="#+id/textViewDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_marginLeft="10dp"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
use drawableleft in your xml of textview
android:drawableLeft="#drawable/settingmenuright"
you can use this layout i have set weightSum property.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3">
<ImageView
android:id="#+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.7">
<TextView
android:layout_toRightOf="#id/icon"
android:id="#+id/textViewSongName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="iconTextview"
android:textColor="#android:color/background_dark"
android:textSize="22dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<TextView
android:id="#+id/textViewArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="textViewArtist"
android:textColor="#android:color/background_dark"
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<TextView
android:id="#+id/textViewDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/background_dark"
android:layout_marginLeft="10dp"
android:text="textViewDuration"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
The layout messes up because you have the ImageView and the TextView in a vertical LinearLayout. Do this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="left"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/album1" />
<TextView
android:layout_toRightOf="#id/icon"
android:id="#+id/textViewSongName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#android:color/white"
android:textSize="22dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textViewArtist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_weight="1"
android:textColor="#android:color/white"
android:textSize="15dp" />
<TextView
android:id="#+id/textViewDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_marginLeft="10dp"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
I have moved the ImageView and TextView in another horizontal LinearLayout

Centering a linearlayout present inside a listview

I have a listview which contains a linearlayout. I am trying to get the linearlayout to the center of the screen(horizontally) but it doesn't work.
How it looks -
Portrait -
Landscape -
I want the linearlayout(which has the text "text" and the two images) to come to the center of the screen(horizontally) in both the orientations.
I've tried using layout_gravity on the linearlayout but it doesn't work.
Here's my code -
<?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="match_parent"
android:orientation="vertical"
android:background="#EEEEEE" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/parentListContainer">
</ListView>
</LinearLayout>
Each listview item -
<?xml version="1.0" encoding="utf-8"?>
<!-- I want this layout centered. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:text="text"/>
<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:orientation="vertical">
<ImageView
android:id="#+id/ivBottle1"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle2"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Please help.
EDIT: Neither gravity="center" works on the listview, nor does layout_gravity="center" on the linearlayout.
<?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="match_parent"
android:orientation="vertical"
android:background="#EEEEEE" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/parentListContainer">
</ListView>
</LinearLayout>
See here for explanation : https://stackoverflow.com/a/3482757/4706693
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:text="text"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle1"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle2"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>

Android - Issue with scrollview

I am using scrollview on my activity. The scrollview contains a LinearLayout and some other views inside that layout. There is another LinearLayout android:id="#+id/linLayoutImagesContainer" used to put images items with 3 images dynamically just like in Gridview with three columns.
All other things are working perfectly. But, If I add more than 12 rows (i,e.36 images) into LinearLayout dynamically then the scrollview becomes blank with no view.
Can anybody help me? Thanks in advance.
My xml layout:
<?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">
<RelativeLayout
android:id="#+id/relLayoutActionBar"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/background_action_bar">
<TextView
android:id="#+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Activity Detail"
android:textColor="#ffffff"
android:textSize="20sp"/>
<ImageView
android:id="#+id/ivButtonBack"
android:layout_width="35dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/back_icon"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="14sp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutTripBanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relLayoutActionBar">
<ImageView
android:id="#+id/imageViewActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="centerCrop"
android:background="#drawable/default_activity_banner"/>
<!--<Button
android:id="#+id/buttonActivityBanner"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#null"/>-->
</RelativeLayout>
<ScrollView
android:id="#+id/parallaxScroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_below="#+id/relLayoutActionBar"
android:layout_above="#+id/relLayoutActionFooter">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="220dp">
<Button
android:id="#+id/buttonActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#null"
android:layout_marginTop="-220dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:alpha="0.9">
<TextView
android:id="#+id/textViewTripDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="10dp"
android:alpha="0.9"
android:background="#ffffffff"
android:text="Activity (Description)"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_margin="10dp"
android:background="#drawable/layout_round_border">
<TextView
android:id="#+id/textViewImages"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="Images (0)"
android:textSize="18sp"
android:textColor="#android:color/white"
android:background="#drawable/layout_left_round_colored"
android:layout_toLeftOf="#+id/viewDate"
/>
<View
android:id="#+id/viewDate"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/textViewVideos"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignEnd="#id/textViewImages"
android:gravity="center"
android:text="Videos (0)"
android:textColor="#ffec6221"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/viewDate"/>
</RelativeLayout>
<LinearLayout
android:id="#+id/linLayoutImagesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relLayoutActionBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/background_action_bar">
<TextView
android:id="#+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Activity Detail"
android:textColor="#ffffff"
android:textSize="20sp"/>
<ImageView
android:id="#+id/ivButtonBack"
android:layout_width="35dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/back_icon"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="14sp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutTripBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="centerCrop"
android:background="#drawable/default_activity_banner"/>
</RelativeLayout>
<ScrollView
android:id="#+id/parallaxScroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="220dp">
<Button
android:id="#+id/buttonActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#null"
android:layout_marginTop="-220dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:alpha="0.9">
<TextView
android:id="#+id/textViewTripDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="10dp"
android:alpha="0.9"
android:background="#ffffffff"
android:text="Activity (Description)"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_margin="10dp"
android:background="#drawable/layout_round_border">
<TextView
android:id="#+id/textViewImages"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="Images (0)"
android:textSize="18sp"
android:textColor="#android:color/white"
android:background="#drawable/layout_left_round_colored"
android:layout_toLeftOf="#+id/viewDate"
/>
<View
android:id="#+id/viewDate"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/textViewVideos"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignEnd="#id/textViewImages"
android:gravity="center"
android:text="Videos (0)"
android:textColor="#ffec6221"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/viewDate"/>
</RelativeLayout>
<LinearLayout
android:id="#+id/linLayoutImagesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

Categories

Resources