【发布时间】:2015-09-23 08:05:21
【问题描述】:
我有一个相对布局:
<RelativeLayout 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" android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context="com.pinder.moffel.pinder.DeleteActivity"
android:id="@+id/deleteBackground">
<com.andtinder.view.CardContainer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tinderview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"/>
</RelativeLayout>
我正在使用库 AndTinder:https://github.com/kikoso/Swipeable-Cards
我已经知道如何添加新卡片,但问题是,由于正在添加新布局,新卡片会显示在其他视图的顶部。
我想在 Activity 加载时添加 3 张卡片,然后在卡片被刷掉时添加一张新卡片在所有其他卡片之后。
如何在 RelativeLayout 中的所有其他视图后面扩展新视图?
一些附加代码:
JAVA 代码
SimpleCardStackAdapter adapter = null;
CardContainer mCardContainer = (CardContainer) findViewById(R.id.tinderview);
adapter = new SimpleCardStackAdapter(this);
CardModel newCard = new CardModel(null, null, image); //image is retrieved before
adapter.add(newCard); //the new card will now be on top of the others, i want it to be behind them
mCardContainer.setAdapter(adapter);
正在添加的 XML 视图
<RelativeLayout
android:id="@+id/global_container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"
tools:src="@drawable/picture1"/>
<View
android:id="@+id/divider_bottom"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="@id/image"
android:background="@color/card_outline" />
<View
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_alignBottom="@+id/layoutButton"
android:layout_below="@+id/divider_bottom"
android:background="@color/card_bg"
/>
<!-- An invisible view aligned to the center of the parent. Allows other
views to be arranged on either side -->
<LinearLayout
android:id="@+id/layoutButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/divider_bottom"
android:gravity="center"
>
<ImageButton
android:id="@+id/image_1"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/denied"
android:padding="10dp"
android:layout_marginRight="80dp"/>
<ImageButton
android:id="@+id/image_2"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/heart"
android:padding="10dp"
android:layout_alignParentRight="true" />
</LinearLayout>
</RelativeLayout>
在另一个问题 (How to inflate a view behind another) 中,答案指出不可能在其他人后面添加视图,但我认为必须有一种方法来实现这一点。
【问题讨论】:
标签: android android-layout android-adapter android-relativelayout