다음은 내 xml 코드입니다. 안에 내 LinearLayout
. 나는 두 개의 자식 뷰를 가지고 있는데, 이는 weightSum
을 사용하여 정렬됩니다. weightSum
으로 인해 너비가 올바르게 정렬 된 ImageView
이 있지만 높이가 문제입니다. 높이가 너비와 같은 치수가되기를 원합니다. static dp
값을 사용하지 않고 해결책이 있습니까?Android 너비와 높이가 같음보기
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<LinearLayout
android:background="@drawable/background_gradien_yellow"
android:weightSum="10"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_weight="6"
android:id="@+id/startbtn"
android:textStyle="bold"
android:alpha="0.8"
android:textColor="#fff"
android:text="@string/start"
android:layout_centerInParent="true"
android:background="@drawable/background_gradient_circular"
android:layout_width="match_parent"
android:layout_height="150dp"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="vertical"
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textColor="@color/White"
android:id="@+id/tv_challange_title"
android:textSize="20sp"
android:text="Early-Bird Challange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_challange_desc"
android:alpha="0.5"
android:textColor="@color/White"
android:textSize="15sp"
android:layout_marginTop="5dp"
android:text="Take 100 steps five times within.. "
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
XML 코드. 사용자 정의 ImageView 사용 –
imageView scaleType을 "center"로 설정하십시오. –