Android 列表项视图未正确显示在线性回收视图中
您好,我有一个水平回收视图,它应该显示一张图片,下面是一个名称。我无法让它工作,因为图像视图显示不同的大小,即使它们有固定的尺寸,并且下面的文本要么不可见,要么位置怪异。下面是模拟器和我的手机的截图 代码: 回收视图所在的cardViewAndroid 列表项视图未正确显示在线性回收视图中,android,android-recyclerview,linearlayoutmanager,Android,Android Recyclerview,Linearlayoutmanager,您好,我有一个水平回收视图,它应该显示一张图片,下面是一个名称。我无法让它工作,因为图像视图显示不同的大小,即使它们有固定的尺寸,并且下面的文本要么不可见,要么位置怪异。下面是模拟器和我的手机的截图 代码: 回收视图所在的cardView <android.support.v7.widget.CardView android:id="@+id/more_cardView_2" android:layout_width="
<android.support.v7.widget.CardView
android:id="@+id/more_cardView_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:visibility="visible"
android:visibility="invisible"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_marginLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="Cast"
android:layout_marginBottom="4dp"/>
<android.support.v7.widget.RecyclerView
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:id="@+id/cast_recyclerView"
android:layout_width="wrap_content"
android:layout_height="135dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
对于水平回收器视图,您可以执行以下操作:
LinearLayoutManager horizontalLayoutManagaer
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
cast_recyclerView.setLayoutManager(horizontalLayoutManagaer);
cast_recyclerView.setAdapter(horizontalAdapter);
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#E0E0E0"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/profile_pic"
tools:background="@android:color/black"
tools:src="@drawable/test"
android:layout_width="100dp"
android:layout_height="135dp"
android:scaleType="centerCrop"/>
<TextView
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:id="@+id/actor_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textStyle="bold"
tools:text="The name of an actor"
android:textSize="12sp"/>
<TextView
android:id="@+id/actor_role"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
tools:text="The character playd by that actor"
android:textSize="12sp"/>
</LinearLayout>
并将您的列表项目.xml更改为以下内容:
LinearLayoutManager horizontalLayoutManagaer
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
cast_recyclerView.setLayoutManager(horizontalLayoutManagaer);
cast_recyclerView.setAdapter(horizontalAdapter);
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#E0E0E0"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/profile_pic"
tools:background="@android:color/black"
tools:src="@drawable/test"
android:layout_width="100dp"
android:layout_height="135dp"
android:scaleType="centerCrop"/>
<TextView
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:id="@+id/actor_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textStyle="bold"
tools:text="The name of an actor"
android:textSize="12sp"/>
<TextView
android:id="@+id/actor_role"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
tools:text="The character playd by that actor"
android:textSize="12sp"/>
</LinearLayout>
在cardView中将recyclerview更改为以下内容:
<android.support.v7.widget.RecyclerView
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:id="@+id/cast_recyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
对于水平回收器视图,您可以执行以下操作:
LinearLayoutManager horizontalLayoutManagaer
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
cast_recyclerView.setLayoutManager(horizontalLayoutManagaer);
cast_recyclerView.setAdapter(horizontalAdapter);
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#E0E0E0"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/profile_pic"
tools:background="@android:color/black"
tools:src="@drawable/test"
android:layout_width="100dp"
android:layout_height="135dp"
android:scaleType="centerCrop"/>
<TextView
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:id="@+id/actor_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textStyle="bold"
tools:text="The name of an actor"
android:textSize="12sp"/>
<TextView
android:id="@+id/actor_role"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
tools:text="The character playd by that actor"
android:textSize="12sp"/>
</LinearLayout>
并将您的列表项目.xml更改为以下内容:
LinearLayoutManager horizontalLayoutManagaer
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
cast_recyclerView.setLayoutManager(horizontalLayoutManagaer);
cast_recyclerView.setAdapter(horizontalAdapter);
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#E0E0E0"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/profile_pic"
tools:background="@android:color/black"
tools:src="@drawable/test"
android:layout_width="100dp"
android:layout_height="135dp"
android:scaleType="centerCrop"/>
<TextView
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:id="@+id/actor_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textStyle="bold"
tools:text="The name of an actor"
android:textSize="12sp"/>
<TextView
android:id="@+id/actor_role"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
tools:text="The character playd by that actor"
android:textSize="12sp"/>
</LinearLayout>
在cardView中将recyclerview更改为以下内容:
<android.support.v7.widget.RecyclerView
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:id="@+id/cast_recyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
Welcome@fgoogle。如果它真的帮助了你,请投票表决。Welcome@fgoogle。如果它真的帮助了你,请投票表决。