Using layout_above in a RelativeLayout

后端 未结 4 717
天命终不由人
天命终不由人 2020-12-24 14:39

Can someone explain to me why the ImageView is not appearing above the LinearLayout?



        
相关标签:
4条回答
  • 2020-12-24 15:11

    This happens when you specify alignment relative to another layout. The solution I found was to go the other direction.

    Instead of telling the ImageView to be above the LinearLayout, tell the LinearLayout to be below the ImageView.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/rev_main"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rev_arrow">
            <!-- some stuff in here -->
        </LinearLayout>
        <ImageView
            android:id="@+id/rev_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/arrow"
            />
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-24 15:12

    I had an similar problem by creating a custom optionsMenu. The simplest way to set z-order of views was to do it programmatically. If you want to switch the order sometimes, your should easily call:

        ImageView yourImageView = (ImageView)findViewById(R.id.rev_arrow);
        yourImageView.bringToFront();
    

    I don´t know if it is adaptive to your application, but in my case it works perfect. If you need more code, let me know.

    0 讨论(0)
  • 2020-12-24 15:26

    The following should work for you:

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/rev_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/arrow"
            android:layout_alignParentTop="true"
            />
        <LinearLayout
            android:id="@+id/rev_main"
            android:layout_width="fill_parent"
            android:layout_below="@id/rev_arrow"
            android:layout_height="wrap_content">
            <!-- some stuff in here -->
        </LinearLayout>
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-24 15:31

    If you have such problem in ListView make sure that you use proper inflation method. Parent view group must be specified for correct inflation.

    mLayoutInflater.inflate(R.layout.listitem, parent, false);
    

    Don't use

    mLayoutInflater.inflate(R.layout.listitem, null);
    
    0 讨论(0)
提交回复
热议问题