我想在Android活动中显示一个包含两个RecycleView的模态。所以我将这个xml文件构建为模态:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/sfondo_app"
tools:context=".it.eresult.decipher.activity.AlertsActivity">
<TextView
android:id="@+id/labelAgent"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List of Agent "
android:background="@color/colorHeaderTable"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_agent_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_marginTop="28dp"/>
<TextView
android:id="@+id/labelReaction"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List of Reaction "
android:background="@color/colorHeaderTable"
android:layout_marginTop="30dp"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_reaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_marginTop="28dp"/>
</RelativeLayout>
使用此代码,我可以看到两个RecycleView被叠加,而不是我想在第二个回收视图下的文本下的RecycleView下显示Text。
可以这样做吗?
答案 0 :(得分:1)
使用LinearLayout
作为RecyclerViews
您还可以将andorid:weight_sum ="1"
分配给RecyclerViews
无论手机的屏幕尺寸有多大,它都会确保您的RecyclerViews
尺寸相同。
样品:
<LinearLayout
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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/sfondo_app"
tools:context=".it.eresult.decipher.activity.AlertsActivity">
<TextView
android:id="@+id/labelAgent"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List of Agent "
android:background="@color/colorHeaderTable"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_agent_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_marginTop="28dp"/>
<TextView
android:id="@+id/labelReaction"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List of Reaction "
android:background="@color/colorHeaderTable"
android:layout_marginTop="30dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_reaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_marginTop="28dp"/>
</LinearLayout>
答案 1 :(得分:0)
您应该使用支持库提供的相对百分比布局。使用方便。例如
<android.support.percent.PercentRelativeLayout
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">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentFrameLayout>
http://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html
答案 2 :(得分:0)
我认为最好的方法是使用具有垂直方向而不是RelativeLayout的LinearLayout,但如果你使用RelativeLayout作为根布局,你应该做一些像:
<RelativeLayout ... >
<TextView
android:id="@+id/labelAgent"
...
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_agent_view"
android:layout_below="@+id/labelAgent"
/>
<TextView
android:id="@+id/labelReaction"
android:layout_below="@+id/recycler_agent_view"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_reaction_view"
android:layout_below="@+id/labelReaction"
/>
</RelativeLayout>