Использование layout_above в RelativeLayout
Может кто-нибудь объяснить мне, почему ImageView не появляется над LinearLayout?
<RelativeLayout
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">
<!-- 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"
android:layout_above="@id/rev_main"
/>
</RelativeLayout>
Я не понимаю.
Ответы
Ответ 1
Это происходит, когда вы указываете выравнивание относительно другого макета. Решение, которое я нашел, состояло в том, чтобы перейти в другое направление.
Вместо того, чтобы сообщать ImageView над LinearLayout, скажите LinearLayout ниже 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>
Ответ 2
Для вас должно работать следующее:
<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>
Ответ 3
У меня была аналогичная проблема, создав пользовательские параметрыMenu. Самый простой способ установить z-порядок просмотров - это сделать это программно. Если вы хотите периодически менять порядок, вы должны легко позвонить:
ImageView yourImageView = (ImageView)findViewById(R.id.rev_arrow);
yourImageView.bringToFront();
Я не знаю, адаптивен ли он к вашему приложению, но в моем случае он работает отлично. Если вам нужно больше кода, дайте мне знать.
Ответ 4
Если у вас есть такая проблема в ListView, убедитесь, что вы используете правильный метод инфляции. Для правильной инфляции необходимо указать группу родительского контроля.
mLayoutInflater.inflate(R.layout.listitem, parent, false);
Не используйте
mLayoutInflater.inflate(R.layout.listitem, null);