【问题标题】:Android : Gridview cuts the edges of the itemsAndroid : Gridview 切割项目的边缘
【发布时间】:2018-09-24 12:12:33
【问题描述】:

我的gridview 有问题,我不明白为什么它会切割项目的边缘而不是调整它们的大小以使其适合。我想在每个屏幕尺寸上看到所有项目。有人有什么主意吗?谢谢

这是我使用的 XML 代码:

<GridView
    android:id="@+id/gridView"
    android:layout_width="0dp"
    android:layout_height="522dp"
    android:columnWidth="120dp"
    android:gravity="center"
    android:horizontalSpacing="0dp"
    android:numColumns="auto_fit"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/cardView2"></GridView>

项目布局:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_margin="0dp"
    android:layout_gravity="center">

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter" />

</android.support.v7.widget.CardView>

【问题讨论】:

  • 显示你的项目布局
  • 能否请您发布您的项目布局?
  • 为gridview设置内边距
  • 添加了项目布局
  • 我看不到您的项目布局代码。

标签: android android-layout gridview


【解决方案1】:

填充添加到您的 CardView 布局

<android.support.v7.widget.CardView 
      xmlns:android="schemas.android.com/apk/res/android"; 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_margin="0dp" 
      android:padding="11dp"
      android:layout_gravity="center"> 

        <ImageView 
           android:id="@+id/image" 
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:scaleType="fitCenter" /> 

 </android.support.v7.widget.CardView>

【讨论】:

  • 感谢这个想法,添加填充没有帮助,我又试了一次,但看起来还是一样:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-07
  • 2018-11-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多