Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ImageView disappears when using layout_above

I'm using RelativeLayout and trying to make few buttons under the image. Why does the ImageView disappear, when I use android:layout_above="@+id/likebutton" in it? How to make it not disappear?

<?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:background="@drawable/listitem_shape" >

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="15dp"
    android:layout_marginBottom="10dp" />

<ProgressBar
    android:id="@+id/progressbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<ImageView
    android:id="@+id/imageview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/likebutton"
    android:layout_below="@+id/title" />

<ImageButton
    android:id="@+id/likebutton"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="@drawable/like"/>

<ImageButton
    android:id="@+id/sharebutton"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/likebutton"
    android:background="@drawable/share" />
</RelativeLayout >
like image 446
Gintas_ Avatar asked Jan 12 '23 05:01

Gintas_


2 Answers

You are setting android:layout_alignParentBottom="true" so you can't use android:layout_above="@+id/likebutton". In short when you set some child view against the parent view, you cannot set other views relative to it. Otherwise it won't reflect.

like image 71
Jatin Malwal Avatar answered Jan 21 '23 20:01

Jatin Malwal


Try this one

<?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="@drawable/listitem_shape"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="15dp"
            android:textStyle="bold" />

        <ProgressBar
            android:id="@+id/progressbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageView
            android:id="@+id/imageview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/likebutton"
            android:layout_below="@+id/title" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/likebutton"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="@drawable/like" />

        <ImageButton
            android:id="@+id/sharebutton"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@+id/likebutton"
            android:background="@drawable/share" />
    </LinearLayout>

</LinearLayout>

Hope this may help

like image 33
gokhanakkurt Avatar answered Jan 21 '23 18:01

gokhanakkurt