Im building a row layout for my ListView and have a problem by it.
Currently my layout looks like this :
XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout_ROW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
>
<ImageView
android:id="#+id/imageView_albumart"
android:layout_alignParentTop="true"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="5dp"
android:background="#color/black"
android:visibility="visible"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/txt_titel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/txt_artist"
android:layout_alignTop="#+id/imageView_albumart"
android:layout_toRightOf="#+id/imageView_albumart"
android:singleLine="true"
android:text="Titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="18dp"
android:textSize="17dp"
android:layout_toLeftOf="#+id/imageView_eq_animation"
android:layout_alignLeft="#+id/txt_artist"
android:layout_alignStart="#+id/txt_artist" />
<TextView
android:id="#+id/txt_artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView_albumart"
android:layout_marginBottom="16dp"
android:layout_toRightOf="#+id/imageView_albumart"
android:text="Artist"
android:singleLine="true"
android:textSize="13dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toLeftOf="#+id/imageView_eq_animation" />
<ImageView
android:id="#+id/imageView_eq_animation"
android:layout_width="30dp"
android:layout_height="70dp"
android:src="#drawable/ic_equalizer1_white_36dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
android:layout_alignParentLeft="#+id/txt_artist"
android:layout_alignBottom="#+id/imageView_albumart" />
<TextView
android:id="#+id/txt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0:00"
android:singleLine="true"
android:textSize="10dp"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="#+id/txt_titel"
android:layout_alignParentRight="true" />
</RelativeLayout>
Now when I want to change the visibility of the imageView_albumart to android:visibility="gone" I get this result :
Can you see where my format problem is ? I just want to hide the imgAlbumart so Title and Artist TextViews stand alone.
Set the visibility of the View to View.INVISIBLE instead of View.GONE
Try Like this, You Can Design the UI With Combination of RelativeLayout and LinearLayout. Do search in Google about design pattern and Usage Of Layouts in Android. You Will get ideas.
<?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:background="#null"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView_albumart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:background="#android:color/darker_gray"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/RelativeLayout_ROW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#null">
<TextView
android:id="#+id/txt_titel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:singleLine="true"
android:text="Titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17dp" />
<TextView
android:id="#+id/txt_artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_titel"
android:layout_marginBottom="16dp"
android:singleLine="true"
android:text="Artist"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="13dp" />
<ImageView
android:id="#+id/imageView_eq_animation"
android:layout_width="30dp"
android:layout_height="70dp"
android:layout_alignBottom="#+id/txt_artist"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="#drawable/ic_game"
android:visibility="gone" />
<TextView
android:id="#+id/txt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageView_eq_animation"
android:singleLine="true"
android:text="0:00"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10dp"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
Yes there is problem in your layout
change your layout to this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout_ROW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imageView_albumart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="5dp"
android:background="#000"
android:visibility="gone"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/txt_titel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView_albumart"
android:text="Titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="18dp"
android:textSize="17sp"
android:layout_toLeftOf="#+id/imageView_eq_animation"
/>
<TextView
android:id="#+id/txt_artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView_albumart"
android:layout_marginBottom="16dp"
android:layout_toRightOf="#+id/imageView_albumart"
android:text="Artist"
android:singleLine="true"
android:layout_below="#+id/txt_titel"
android:textSize="13dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toLeftOf="#+id/imageView_eq_animation" />
<ImageView
android:id="#+id/imageView_eq_animation"
android:layout_width="30dp"
android:layout_height="70dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="visible"
android:layout_alignParentLeft="#+id/txt_artist"
android:layout_alignBottom="#+id/imageView_albumart" />
<TextView
android:id="#+id/txt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0:00"
android:singleLine="true"
android:textSize="10dp"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="#+id/txt_titel"
android:layout_alignParentRight="true" />
it will do..
Related
I have some pop ups in my project which work perfectly, but this one seems to not work, he only shows the buttons, the textviews don't appear (Sorry for bad eng) I tried to use other layouts, but don't looks good at all... what I wanna do is simple use 3 textviews in the middle of screen, if you guys could help me with that i would be glad
popadd.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/dialog_round">
<ImageButton
android:id="#+id/btCancelar"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/cancel"
android:tint="#ffffff"
android:background="#drawable/round_button"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="90dp" />
<ImageButton
android:id="#+id/btEnviar"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/certo"
android:tint="#ffffff"
android:background="#drawable/round_button"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adicionar amigo"
android:textSize="70px"
android:textColor="#454545"
android:layout_marginTop="190dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enviar solicitação de amizade para"
android:textSize="40px"
android:textColor="#454545"
android:layout_marginTop="240dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvNome"
android:text="Carregando..."
android:textSize="40px"
android:textColor="#454545"
android:layout_marginTop="270dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Try this in your code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/dialog_round">
<ImageButton
android:id="#+id/btCancelar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="90dp"
android:background="#drawable/round_button"
android:padding="5dp"
android:src="#drawable/cancel"
android:tint="#ffffff"/>
<ImageButton
android:id="#+id/btEnviar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="30dp"
android:background="#drawable/round_button"
android:padding="5dp"
android:src="#drawable/certo"
android:tint="#ffffff"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Adicionar amigo"
android:textColor="#454545"
android:textSize="70px"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Enviar solicitação de amizade para"
android:textColor="#454545"
android:textSize="40px"/>
<TextView
android:id="#+id/tvNome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Carregando..."
android:textColor="#454545"
android:textSize="40px"/>
</LinearLayout>
</RelativeLayout>
I have an issue trying align textView to the center of layout: when I try to do this - it has a conflict with a button on the left - if text is too long - it become hidden under the button. Text length can be very different and I need it in the center of layout but not under/on the button.
Here is the xml file of activity layout:
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false" />
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="5dp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_content_scroll_view"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/item_content_image"
android:src="#drawable/ic_no_thumbnail"
android:maxHeight="125dp"
android:maxWidth="125dp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subtitle"
android:layout_alignTop="#+id/item_content_image"
android:layout_toRightOf="#+id/item_content_image"
android:layout_toEndOf="#+id/item_content_image"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_pubdate"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date"
android:layout_below="#+id/item_content_subtitle"
android:layout_alignLeft="#+id/item_content_subtitle"
android:layout_alignStart="#+id/item_content_subtitle"
android:textSize="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="blabla"
android:layout_below="#+id/item_content_pubdate"
android:layout_alignStart="#+id/item_content_pubdate"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try using LinearLayout with layout-weight for this to avoid conflict. Change your first relativelayout to below one
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="7">
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:background="#drawable/chemist" />
<TextView
android:id="#+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5"
android:autoText="false"
android:gravity="center"
android:maxLines="2"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black"
android:textStyle="bold" />
</LinearLayout>
Change Your RelativeLayout to LinearLayout and use android:layout_weight attribute of layout to do this.
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
>
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/chemist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
android:autoText="false"/>
</LinearLayout>
Make the layout_gravity of the textview item_content_title as "center_horizontal".
And add android:layout_toLeftOf="#+id/item_content_title" under the ImageButton item_content_back_button.
Hope it was what you wanted.
Your Action bar layout has to be like this-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp" />
<TextView
android:toRightOf="#id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true" />
</RelativeLayout>
I'm trying to use this lib https://github.com/traex/RippleEffect. I tried the sample and everything works fines but when I try to use this with more views inside the RippleView like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ripple="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:id="#+id/drive_layoutT"
android:layout_height="72dp"
android:weightSum="1"
android:background="#fff"
android:orientation="horizontal">
<com.andexert.library.RippleView
android:id="#+id/rippleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ripple:rv_color="#797979">
<LinearLayout
android:layout_width="fill_parent"
android:id="#+id/drive_layout"
android:layout_height="72dp"
android:weightSum="1"
android:background="#fff"
android:orientation="horizontal">
<ImageView
android:id="#+id/drive_icon"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:padding="4dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="71dp"
android:layout_marginLeft="14dp">
<ImageView
android:id="#+id/drive_menu_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="true"
android:paddingRight="10dp"
android:src="#drawable/button_overflow_menu"
android:layout_marginRight="2dp" />
<View
android:layout_width="22dp"
android:layout_height="22dp"
android:id="#+id/drive_badge"
android:padding="8dp"
android:background="#drawable/circle"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/drive_menu_btn"
android:layout_toStartOf="#+id/drive_menu_btn" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/drive_name"
android:textColor="#color/grey_list_item_title"
android:textSize="16sp"
android:ellipsize="end"
android:singleLine="true"
android:layout_alignTop="#+id/drive_menu_btn"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/drive_spinner"
android:layout_toStartOf="#+id/drive_spinner" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/drive_details"
android:textColor="#color/grey_list_item_details"
android:textSize="10sp"
android:ellipsize="end"
android:singleLine="true"
android:layout_below="#+id/drive_name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/drive_badge"
android:layout_toStartOf="#+id/drive_badge" />
<ProgressBar
style="#style/CustomProgressBar"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:id="#+id/drive_progress_bar"
android:layout_below="#+id/drive_details"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:layout_marginRight="16dp"
android:indeterminate="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="9"
android:id="#+id/drive_badge_text"
android:layout_marginRight="6.5dp"
android:layout_marginEnd="6dp"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/drive_badge"
android:layout_alignEnd="#+id/drive_badge" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+"
android:id="#+id/drive_badge_plus"
android:textSize="7sp"
android:layout_marginRight="3dp"
android:layout_marginEnd="2dp"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/drive_badge"
android:layout_alignEnd="#+id/drive_badge" />
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/drive_spinner"
android:layout_alignBottom="#+id/drive_details"
android:layout_toLeftOf="#+id/drive_badge"
android:layout_toStartOf="#+id/drive_badge"
android:indeterminate="false"
android:layout_marginBottom="3dp" />
</RelativeLayout>
<View
android:id="#+id/drive_divider"
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:background="#color/grey_divider"
android:layout_marginTop="0dp"
android:layout_marginLeft="8dp" />
</LinearLayout>
</LinearLayout>
</com.andexert.library.RippleView>
</LinearLayout>
The ripple effect doesn't fire onClick, if I make a long press click I can see that the ripple effect happens. So this leads to a conclusion which is that this delay is caused because the RippleView is loading all the views inside.
How can I fixe this? Or is there anything I'm getting wrong or any work around for this issue?
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>
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...