【发布时间】:2016-06-28 22:25:28
【问题描述】:
我有一个
1. Framelayout(frame1) in which I am inflating a RecyclerView layout with weight 0.5
2. Framelayout(frame2) with visibility gone and weight 0.5
尽管 frame2 消失了,但我的 Recyclerview 只占据了一半的宽度。如果我使用 listview 而不是 RecyclerView,我就没有这个问题。谁能建议如何让 Recyclerview 占据整个宽度?
编辑: 如果我滚动 recyclerview ,它会按预期占据整个宽度。
适配器
@Override
public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item, parent, false);
ListViewHolder tvh = new ListViewHolder (v);
return tvh;
}
main_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/frame1"
android:layout_width="0dp" // If I put match_parent here it works
android:layout_height="match_parent"
android:layout_weight="0.5"
/>
<FrameLayout
android:id="@+id/frame2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:visibility="gone" />
</LinearLayout>
frame1_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
recycler_item
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="5dp" >
<ImageView
android:id="@+id/imageIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_main" />
<TextView
android:id="@+id/textName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:layout_toRightOf="@+id/imageIcon"
android:textSize="14sp" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text="Test"
android:layout_below="@+id/textName"
android:textSize="12sp" />
</RelativeLayout>
【问题讨论】:
-
你试过
wrap_content吗?
标签: android android-recyclerview