1

원하는 너비 치수 만 지정하고 자동 높이를 지정하는 PercentRelativeLayout을 사용할 수 있습니까?너비 만 지정하는 PercentRelativeLayout 사용 (heigh auto)

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
    android:id="@+id/earthImageView" 
    app:layout_widthPercent="30%" 
    android:src="@drawable/earth" 
    android:layout_alignParentRight="true" 
    android:adjustViewBounds="true"/> 
</android.support.percent.PercentRelativeLayout > 

뷰가 올바른 폭을 가지고 있지만 내가 레이아웃 경계를 확인하면 나는 높이가 MATCH_PARENT 것을 볼 수 있습니다

나는이 일을 의미합니다. 모자 android : adjustViewBounds = "true"가 작동하지 않습니다.

app : layout_widthPercent = "WRAP_CONTENT"를 추가하려고했지만 효과가 없습니다.

감사합니다.

편집 :

<ImageView 
     android:id="@+id/earthImageView" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     app:layout_heightPercent="20%" 
     android:src="@drawable/earth" 
     android:adjustViewBounds="true"/> 

답변

1

내가 제대로 이해하면 폭을 지정하려면 무엇이든지 adjustViewBounds에 자동으로 설정 높이가 당신을 제공하는 경우 :

역 상황을 수행 할 때 문제가 끄트머리.

그런 경우가 있다면, 다음은 당신이 원하는 일을해야는 (나는 wrap_content하는 레이아웃과 이미지 뷰 높이를 모두 설정 한)를 :

<android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/earthImageView" 
     android:layout_height="wrap_content" 
     app:layout_widthPercent="30%" 
     android:src="@drawable/lapin" 
     android:layout_alignParentRight="true" 
     android:adjustViewBounds="true"/> 
</android.support.percent.PercentRelativeLayout > 
+0

가! 덕분에 작동하는 것 같다! – NullPointerException

+0

btw 너비 대신 높이 비율로 시도하면 ... 같은 오류가 발생합니다. 질문에 새로운 문제를 추가했습니다. 제발 테스트 할 수 있습니까? – NullPointerException

+0

그건 좋은 질문 @ NullPointerException, 그것도 작동하지 않는 것 같습니다. 이미지의 비율을 알고 있습니까? 그렇다면 layout_width (및 layout_height)를 제거하고 'app : layout_aspectRatio = "80 %"'예를 들어 – mVck