2015-11-12 10 views
6

私はサポートライブラリからPercentRelativeLayoutを試しています。the docsは、app:layout_widthPercentプロパティを指定するようにお願いしています。しかし、私がそれをすると、Android Studioはlayout_widthが指定されていないという赤い警告を表示します。PercentRelativeLayout - layout_widthが表示されない警告

警告を抑制する以外に、方法がありますか?例えば

:TextInputLayoutについて説明

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

     <android.support.design.widget.TextInputLayout 
      android:id="@+id/expiry_month_wrapper" 
      app:layout_widthPercent="25%" 
      android:layout_height="wrap_content"> 
      <EditText 
       android:id="@+id/expiry_month_editText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxLength="2" 
       android:hint="@string/month" 
       android:focusable="true" 
       android:inputType="number"/> 
     </android.support.design.widget.TextInputLayout> 

     <!-- more TextInputLayout fields --> 

    </android.support.percent.PercentRelativeLayout> 

警告。

+0

テストコードの私の例です。それは何か悪い、あるいはただの警告をもたらしますか? – pratz9999

答えて

1

私はこれが古い質問です実現 - しかし、ちょうど私はそれが皆のために利用できることを確認したい、この問題:)追加

に遭遇しましたPercentRelativeLayoutを表示すると、テキストエディタに視覚的なエラーが表示されます。画面上でレンダリングが失敗することもあります。進んでエミュレータを実行すると、可視性の問題が解決されます。

エラーを解決するにはandroid:layout_width="0dp"を追加してください。widthPercentheightPercentが適切に設定されていれば、問題は発生しません。

は、ここで私は同じ問題を持っている

  android:text="Label label" 
      android:id="@+id/btn1" 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_alignParentTop="true" 
      app:layout_widthPercent="50%" 
      app:layout_heightPercent="30%" 
      android:textSize="17sp"/> 

     <Button 
      android:text="Other other other" 
      android:id="@+id/btn2" 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_toRightOf="@id/btn1" 
      app:layout_widthPercent="50%" 
      app:layout_heightPercent="30%" 
      android:textSize="17sp"/> 
8

慣習的に、layout_widthとlayout_heightは、それぞれPercentRelativeLayoutのapp:layout_widthPercentとapp:layout_aspectRatioで機能的に無視されている場合でも含めなければなりません。

あなたの場合、app:layout_widthPercentを単独で使用することで、android:layout_widthに任意の数の密度に依存しないピクセルを設定して、警告を取り除くことができます。例えば

: アンドロイド:layout_width =「0dp」

+3

しかし、注意してください...例えば、 "wrap_content"はPercentRelativeLayoutで非常に特殊な意味を持ちます。フィールドは完全に無視されません。 – lilbyrdie

関連する問題