Zunächst einmal müssen Sie unten eine ImageView
wie Unterklasse:
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
}
}
Verwenden Sie diese Datei im XML-Datei.
<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>
Stellen Sie sicher, Ihre MyImageView
Höhe und Breite match_parent
sein muss.
Sie können Ihr benutzerdefiniertes Zeilenelementlayout anpassen – Piyush