【问题标题】:how to make responsive recyclerView which will be same on tablet and android device如何制作在平板电脑和安卓设备上相同的响应式 recyclerView
【发布时间】: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>

我如何制作响应式布局

【问题讨论】:

标签: android android-studio android-layout android-fragments android-recyclerview


【解决方案1】:

嘿,亲爱的,您只需将 RecyclerView 与虚拟项目一起使用。您必须专注于每次要用于在 RecyclerView 中显示项目的布局。如果您为该项目制作响应式布局,您的整个 RecyclerView 将是响应式的。

【讨论】:

    【解决方案2】:

    在您的代码中,您使用了dp,它因设备而异。因此,您的布局不会根据您的要求进行调整。 要解决它,您可以尝试使用这个 android library 并使用该 lib dp 值重新定义所有 xml dp 值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 2016-06-18
      相关资源
      最近更新 更多