【发布时间】:2018-04-27 16:07:05
【问题描述】:
我使用 recylerview 和 gridlayout 管理器,每行都有卡片视图,我的行视图(子视图)根本没有响应。
我想以这样的方式显示 15 个卡片视图,在纵向模式下,我的所有 15 个子视图都应该可见,并且我的 recyclerview 不应该是可滚动的,而在横向模式下它应该反之亦然(应该是可滚动的)
我已经尝试了很多关于 SO 的建议,但似乎没有任何效果。
目前在不同屏幕尺寸上的表现如下
在上面附加的屏幕截图中,第 3 列、第 4 和第 5 行不可见
在上面给定的屏幕中,我的用户界面非常适合纵向模式,但在横向模式下我看不到所有卡片视图。
在上面附加的屏幕截图中,第 5 行不可见,并且在横向模式下存在一些响应错误。 cardview.xml
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="127dp"
android:layout_height="118dp"
android:layout_margin="5dp"
cardview:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/mReminder_Image_Id"
android:layout_width="match_parent"
android:layout_height="90dp"
android:scaleType="fitXY"
android:background="#ffffff"/>
<TextView
android:id="@+id/mReminder_Text_Id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#2d2d2d"
android:textSize="13sp"
android:text="Reminder texts"/>
</LinearLayout>
</android.support.v7.widget.CardView>
fragment_reminders.xml
<LinearLayout 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="match_parent"
android:orientation="vertical"
tools:context=".Fragments.Reminders">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reminders"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/tab_background"
android:layout_gravity="center" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="@+id/mRecyclerView_id"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
谁能指导我解决这个问题。 谢谢。
【问题讨论】:
-
@Kling Klang 你对这个问题有什么想法
-
有一种方式你可能不喜欢,你应该为不同的屏幕尺寸创建不同的布局或使用协调器布局,也使用包装内容而不是设置特定值
-
我们可以设计支持多种屏幕尺寸的应用程序,那我为什么要针对不同的屏幕进行多种设计。
-
如果你能设计
supporting multiple screen sizes它应该可以工作 -
总之,你需要为不同的屏幕尺寸设计不同的布局。 [Android 开发者网站][1] 上有关于该主题的良好文档 但是,您看到这种行为的原因是因为您专门将 XML 中的 ImageView 的大小定义为
90dp,TextView 位于13sp所以无论方向如何,每张卡片的视图大小都将约为103dp。 [1]:developer.android.com/training/multiscreen/screensizes
标签: android android-recyclerview android-cardview