2015-09-10 2 views
2

Я пробовал использовать библиотеку поддержки процентов, как подробно here и here. Он отлично работает в дизайнере Android Studio, но когда я пытаюсь установить мое приложение в свой телефон, ничего не отображается, а пустой экран. В чем проблема?Андроид поддержки библиотеки пустой экран на фактическом устройстве

Edit:

Я добавил следующие строки в моих Gradle зависимостей между файлами.

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' 

А вот мой фрагмент макета:

<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:

Хорошо, я завышены точно такой же макет из Activity с помощью setContentView, и она отлично работает. Кажется, что проблема возникает только тогда, когда я пытаюсь использовать PercentRelativeLayout в макете Fragment. Похоже, что LayoutInflater неправильно рисует макет с элементами PercentRelativeLayout, но я все еще не уверен и продолжаю расследовать.

+0

Опубликовать код. Также ознакомьтесь с этой демонстрацией http://code2concept.blogspot.in/2015/08/android-percent-support-lib-sample.html, если у вас что-то отсутствует :-) – nitesh

+0

Привет, @nitesh, спасибо за ваш ответ. Я отредактировал свой ответ, чтобы включить соответствующий код. –

+0

Его время сообщить об ошибке для PercentRelativeLayout, раздувая проблемы во Фрагментах. – ColinWa

ответ

0

Это не очень хорошее решение, но я решил эту проблему, просто избавившись от фрагмента и сделав его полноценной деятельностью.

+0

Пожалуйста, напишите здесь ошибку: https://code.google.com/p/android/issues с небольшим примером проблемы (так что я могу воспроизвести это). Если LayoutInflater действительно не может обрабатывать процентный макет, я постараюсь это исправить. – gruszczy

+0

Решение должно работать для фрагментов, как указывает проблема. Избавление от фрагмента активности не является решением. он всегда работал на активность – ColinWa

Смежные вопросы