PercentRelativeLayout okay on Emulator, not okay on phone

后端 未结 2 1945
后悔当初
后悔当初 2021-01-26 02:00

I\'ve just implemented PercentRelativeLayout. I\'ve added: compile \'com.android.support:percent:24.2.0\' to the gradle so Android Studio at least reco

相关标签:
2条回答
  • 2021-01-26 02:27

    Finally figured this out. Problem was actually in the XML. Posting here for reference in hopes someone will find it helpful in the future.

    The problem came from setting layout_heightPercent and layout_widthPercent. For some reason this does not allow the view in question to display. I do not believe it has anything to do with scaling the aspect ratio as the problem exists with buttons as well (with no aspect ratio to maintain.)

    But if you're having visibility problems with a PercentRelativeLayout, see below.

        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btnIntro"
            android:src="@drawable/button1" 
            app:layout_widthPercent="30%"       // MUST SET ONE 
            app:layout_heightPercent="25%"      // OR OTHER NOT BOTH
            android:layout_below="@id/textMainSubTitle"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp" />
    
    0 讨论(0)
  • 2021-01-26 02:47

    Inspired by BR89, the solution to my issue was actually use "android:src" instead of "app:srcCompat" and also specifying "0dp" on "android:layout_width"

    But putting both "app:layout_widthPercent" and "app:layout_heightPercent" will not have any issue on my physical device though.

    <android.support.percent.PercentRelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/splash">
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_widthPercent="50%"
            app:layout_heightPercent="50%"
            app:layout_marginTopPercent="25%"
            app:layout_marginLeftPercent="25%"
            android:src="@drawable/logo"/>
    </android.support.percent.PercentRelativeLayout>
    
    0 讨论(0)
提交回复
热议问题