![](/img/trans.png)
[英]How to make responsive Android application which is used in mobile and also in tablet?
[英]how to make responsive recyclerView which will be same on tablet and android device
我正在使用 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>
我如何制作响应式布局
嘿,亲爱的,您只需将 RecyclerView 与虚拟项目一起使用。 您必须专注于每次将用于在 RecyclerView 中显示项目的布局。 如果你为那个项目做一个响应式布局,你的整个 RecyclerView 将是响应式的。
在您的代码中,您使用了不同设备的dp
。 因此,您的布局不会根据您的要求进行调整。 要解决它,您可以尝试使用此 android库并使用该 lib dp 值重新定义所有 xml dp 值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.