Vernon Gutierrez Vernon Gutierrez - 9 days ago 5
Android Question

Android Percent Support Library Blank Screen on Actual Device

I tried using the Percent Support Library as detailed here and here. It works nicely in the Android Studio designer, but when I try to install my app into my phone, nothing is showing but an empty screen. What might the problem be?

Edit:

I've added the following lines in my gradle file dependencies.

compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:percent:23.0.0'


And here is my fragment layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="org.atpms.fairfare.ReportFragment"
android:id="@+id/fragment_report" >

<ProgressBar android:id="@+id/report_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_marginBottom="8dp" android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />

<RelativeLayout
android:id="@+id/report_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/reportButton"
android:gravity="center">

<ImageView
android:id="@+id/report_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="@drawable/report"
android:adjustViewBounds="true" />

<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/report_background"
android:layout_alignBottom="@+id/report_background"
android:layout_alignLeft="@+id/report_background"
android:layout_alignStart="@+id/report_background"
android:layout_alignRight="@+id/report_background"
android:layout_alignEnd="@+id/report_background">

<EditText
android:id="@+id/plateNumberField"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="58%"
app:layout_heightPercent="14%"
app:layout_marginTopPercent="20%"
app:layout_marginLeftPercent="36%"
android:textColor="@color/plate_number"
android:background="@null"
android:gravity="center"
android:textSize="24sp"
tools:ignore="TextFields"/>

<ImageView
android:id="@+id/meterPictureButton"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="12%"
app:layout_heightPercent="15.5%"
app:layout_marginTopPercent="38%"
app:layout_marginLeftPercent="84%"
android:src="@drawable/camera" />

<ImageView
android:id="@+id/meterPicture"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="97.2%"
app:layout_heightPercent="42%"
app:layout_marginTopPercent="55.8%"
app:layout_marginLeftPercent="1.6%"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />

</android.support.percent.PercentRelativeLayout>

</RelativeLayout>

<Button
android:id="@+id/reportButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/report"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="@drawable/report_button"
android:textSize="20sp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textColor="@color/button_text"
android:textAllCaps="false"
android:gravity="center"
tools:ignore="UnusedAttribute" />

</RelativeLayout>

</RelativeLayout>


Update:

Ok, I've inflated the exact same layout from an
Activity
using
setContentView
, and it works fine. It seems that the problem only arises when I try to use the
PercentRelativeLayout
in a
Fragment
layout. It appears that
LayoutInflater
isn't correctly inflating a layout with
PercentRelativeLayout
elements, but I'm still unsure and continuing to investigate.

Answer

It's not a very nice solution, but I solved this problem by just getting rid of the fragment, and making it a full-blown activity.