私はRecyclerView
とGridLayoutManager
を試しています。GridLayoutManager同じイメージサイズ
:
これを可能にするGridLayoutManager
の要素は何ですか? RecyclerView
を入力するために使用する個々のアイテムXMLを変更しますか?あなたは以下のようにImageView
をサブクラス化する必要があるすべての
私はRecyclerView
とGridLayoutManager
を試しています。GridLayoutManager同じイメージサイズ
:
これを可能にするGridLayoutManager
の要素は何ですか? RecyclerView
を入力するために使用する個々のアイテムXMLを変更しますか?あなたは以下のようにImageView
をサブクラス化する必要があるすべての
まず:
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
public class MyImageview extends ImageView {
public MyImageview (Context context) {
super(context);
}
public MyImageview (Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyImageview (Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); // Snap to
// width
}
}
XMLファイルで、このファイルを使用します。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.app.MyImageview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageBackground"
android:scaleType="centerCrop"/>
</LinearLayout>
あなたMyImageView
高さと幅がmatch_parent
でなければならないことを確認してください。
ありがとうございます。私はそれにショットをつけますが、実際にはどこに配置されていますか?あなたがしているのは親にマッチしていることだけです...あなたが間違っていると言っているのではなく、各画像を固定サイズ – tccpg288
カスタムの行アイテムのレイアウトをカスタマイズできます – Piyush