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
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" />
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>