Es wurde oft in SO gefragt, wie Padding in GridView
zu entfernen, aber keine der Antworten für mich arbeiten.Entfernen Sie Padding in GridView
Ich habe eine GridView
, und die Anzahl der Spalten und die Gesamtbreite des Rasterlayouts festlegen. Benötigen Sie Artikel mit 66dp
x 66dp
Größe. Irgendwie sind Gegenstände quadratisch, aber kleiner ist das 66x66 und es gibt eine massive Polsterung um sie herum. Warum?
int zz = .. // number of columns comes from outside
gridview.setNumColumns(zz);
LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams)gridview.getLayoutParams();
linearParams.width=66*zz;
gridview.setLayoutParams(linearParams);
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="66dp"
android:layout_marginRight="0dp"
android:layout_marginLeft="108dp"
android:layout_marginBottom="0dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:columnWidth="66dp"
android:gravity="center"
android:horizontalSpacing="0dp"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="horizontal"
android:stretchMode="none"
android:verticalSpacing="0dp"
android:listSelector="@null"
android:scaleType="centerCrop">
</GridView>
</LinearLayout>
</HorizontalScrollView>
Artikel Prototyp
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="66dp" android:layout_height="66dp">
<ImageView
android:id="@+id/icon"
android:layout_width="66dp"
android:layout_height="66dp"
android:padding="0dp"
android:background="@android:color/holo_orange_light"/>
</RelativeLayout>
Shreen Schuss
einen Adapter Mit dem Inhalt/Bilder zu laden.
@Override
public void onBindViewHolder(RatingHolder ratingHolder, int i) {
ratingHolder.icon.setImageResource(R.drawable.asdf);
//ratingHolder.icon.setAdjustViewBounds(true);
}
Welchen Code verwenden Sie, um das Bild zu laden? –
Hinzugefügt den Code unten, mit Adapter sowieso –