Answer the question
In order to leave comments, you need to log in
Why are view dimensions zero?
I want to make my RelativeLayout, the width of which will always be equal to the height, that is, it will be square. To do this, I inherit from it and override onMeasure
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int h = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(h, h);
}
}
<hakito.autosim.views.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:background="@drawable/btn_back"
android:clickable="true"
android:padding="2dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image"
/>
</hakito.autosim.views.SquareRelativeLayout>
Answer the question
In order to leave comments, you need to log in
well in your code i have
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image"
/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question