【发布时间】:2018-10-13 13:30:56
【问题描述】:
我正在使用 cardview 制作 recyclerView,它工作正常。但这适用于 android 设备,而且这个 recyclerView 不响应平板电脑的大小。我如何制作 recyclerview 的响应式布局,它将显示与手机和平板电脑中相同的产品?我怎么能这样做? 这是我的 recyclerView xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvTopBrands"
android:text="@string/top_brand"
android:textAlignment="center"
android:layout_marginTop="5dp"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold|italic"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvTopBrandProducts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvTopBrands"
app:layout_constraintVertical_bias="0.0" />
</LinearLayout>
这是我的 recyclerView 代码:
final JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,
URLs.viewAllLatestProduct,null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
setLatestProductAdapter(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
这是我的 cardView 布局:
<android.support.v7.widget.CardView android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="2dp"
android:background="@android:color/holo_orange_dark">
<ImageView
android:id="@+id/ivTopBrand"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:padding="2dp"
android:background="@color/white"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_feature_brand" />
</LinearLayout>
我如何制作响应式布局
【问题讨论】:
-
不响应是什么意思?
-
LinearLayout这样的布局在第一个粘贴的 xml 中似乎没用。你不需要那个。 -
嗨嗅探器!我应该使用我的适配器吗?
标签: android android-studio android-layout android-fragments android-recyclerview