2016-07-03 7 views
0

PercentRelativeLayoutを実装しました。私は、compile 'com.android.support:percent:24.2.0'をgradleに追加して、Android Studioが少なくともそのビューを認識できるようにしました。 Google APIを追加しました。PercentRelativeLayoutエミュレータで大丈夫です。電話では大丈夫ではありません。

レンダリングに問題があります。エミュレータでは、私のディスプレイが正常に動作します。 Android 4ishを実行している古い携帯電話にインストールすると、TextViewが表示されますが、画像ビューは表示されません。プレビューで

は(デザイン]タブで)ImageViewsをレンダリング私はこれがちょうど仕事をしていたように感じAPI 24

私はAPI 23に切り替えたときに表示されますが、ではありません。これに関する既知の修正?残念ながら、私のレイアウトを拡大するにはビューが不可欠です。

EDIT:いくつかのAndroidスタジオを再起動すると、プレビューが突然再現されます。何も変えなかった

レイアウトは、API 16までのすべての方法でプレビューで機能しますが、まだ電話では機能しません。 ImageViewsが表示されません。

<LinearLayout 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="fill_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.y" 
tools:showIn="@layout/app_bar_main" 
android:background="#FFF" 
android:weightSum="1" 
android:orientation="vertical"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/scrollView" 
    android:scrollIndicators="top"> 

    <android.support.percent.PercentRelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="This text appears correctly" 
      android:textSize="28sp" 
      android:id="@+id/textMainTitle" 
      android:layout_gravity="center" 
      android:layout_alignParentTop="true" 
      android:textColor="#ffffff" 
      android:singleLine="true"/> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="As does this text" 
      android:id="@+id/textMainSubTitle" 
      android:layout_gravity="center_horizontal" 
      android:layout_below="@id/textMainTitle" 
      /> 


     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnIntro" 
      android:src="@drawable/button1" //DOES NOT APPEAR IN PHONE 
      app:layout_widthPercent="30%" 
      app:layout_heightPercent="25%" 
      android:layout_below="@id/textMainSubTitle" 
      android:layout_marginStart="10dp" 
      android:layout_marginLeft="10dp" /> 

    </android.support.percent.PercentRelativeLayout> 

</ScrollView> 


</LinearLayout> 
+0

レイアウトのxmlをデバッグするのに役立つ場合は、レイアウトxmlを含める必要があります。 – ianhanniballake

+0

フェアポイント。追加された – BR89

答えて

2

以下

XMLは、最後にこれを考え出しました。問題は実際にはXMLにありました。誰かが将来的に役立つことを期待して参考にしてここに投稿してください。

layout_heightPercentlayout_widthPercentの設定に問題があります。何らかの理由で、これは問題のビューを表示できません。

しかし、PercentRelativeLayoutの視認性に問題がある場合は、以下を参照してください。これは、ボタンの問題が存在するため、アスペクト比のスケーリングとは何の関係もありません。

しかし、両方置く代わりに:「SRCアンドロイド」BR89に触発

<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

は、私の問題を解決するには、実際に使用した「アプリ:srcCompat」とも上の「0dp」指定「layout_widthアンドロイド」 「app:layout_widthPercent」と「app:layout_heightPercent」は物理デバイスに問題はありません。

<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> 
関連する問題