我正在尝试使用“滚动视图”和“网格布局”创建布局。我正在使用2列和3行。
问题是一栏显示没问题,但第二栏找不到,因为它没有出现在应用程序中。
图片供参考:
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context=".bikeList">
<ScrollView
android:id="@+id/scrolView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:columnCount="2"
app:rowCount="3">
<android.support.v7.widget.CardView
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bikeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/superpower_sp110_cheetah" />
<TextView
android:id="@+id/bikeName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Super Power SP 110 Cheetah"
android:layout_below="@id/bikeImage"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/bikeType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeName"
android:text="Bike type"/>
<TextView
android:id="@+id/bikeTypeAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Manual"
android:layout_below="@id/bikeType"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/condition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeTypeAnswer"
android:text="Condition"/>
<RatingBar
android:id="@+id/conditionRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/condition"
android:numStars="5"
android:rating="4"
style="?android:attr/ratingBarStyleSmall"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bikeImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/superpower_sp110_cheetah" />
<TextView
android:id="@+id/bikeName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Super Power SP 110 Cheetah"
android:layout_below="@id/bikeImage2"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/bikeType2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeName2"
android:text="Bike type"/>
<TextView
android:id="@+id/bikeTypeAnswer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Manual"
android:layout_below="@id/bikeType2"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/condition2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeTypeAnswer2"
android:text="Condition"/>
<RatingBar
android:id="@+id/conditionRating2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/condition2"
android:numStars="5"
android:rating="4"
style="?android:attr/ratingBarStyleSmall"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bikeImage3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/superpower_sp110_cheetah" />
<TextView
android:id="@+id/bikeName3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Super Power SP 110 Cheetah"
android:layout_below="@id/bikeImage3"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/bikeType3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeName3"
android:text="Bike type"/>
<TextView
android:id="@+id/bikeTypeAnswer3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Manual"
android:layout_below="@id/bikeType3"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/condition3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeTypeAnswer3"
android:text="Condition"/>
<RatingBar
android:id="@+id/conditionRating3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/condition3"
android:numStars="5"
android:rating="4"
style="?android:attr/ratingBarStyleSmall"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bikeImage4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/superpower_sp110_cheetah" />
<TextView
android:id="@+id/bikeName4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Super Power SP 110 Cheetah"
android:layout_below="@id/bikeImage4"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/bikeType4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeName4"
android:text="Bike type"/>
<TextView
android:id="@+id/bikeTypeAnswer4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Manual"
android:layout_below="@id/bikeType4"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/condition4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bikeTypeAnswer4"
android:text="Condition"/>
<RatingBar
android:id="@+id/conditionRating4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/condition4"
android:numStars="5"
android:rating="4"
style="?android:attr/ratingBarStyleSmall"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v7.widget.GridLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
答案 0 :(得分:0)
默认情况下,Cardview在单个列中显示“项目”,尝试在活动脚本中定义自己的自定义适配器类...