7
ござい質問How to make ConstraintLayout work with percentage values?であり、その答えは割合に使用する方法を示しています。アンドロイド - ConstraintLayoutパーセント使用してdimens
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"/>
しかしを、あなたはパーセンテージをハードコーディングしたが、それはないDIMENリソースを使用しない場合作業。
Float types not allowed (at 'guideline_perc' with value 0.5).
あなたは1で値を交換した場合、同様のエラーが返されます:
Integer types not allowed (at 'guideline_perc' with value 1).
あなたが設定するにはどうすればよいあなたは次のエラーを取得する
<!-- inside the layout -->
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="@dimen/guideline_perc"/>
<!-- inside dimens.xml -->
<dimen name="guideline_perc>0.5</dimen>
レイアウトに値をハードコーディングすることなくパーセンテージ?
:整数を使用している場合
<item name="guideline_perc" type="dimen">0.5</item>
を、
integer
リソースが最高の仕事とは両方のアプローチでディメンションリソースが生成されるため、IDEバグまたはビルドツールのバグです。 – CommonsWareリソースを2次元として定義するには、測定単位が必要です。 'dimen'型の項目として定義することはできません。さらに、 'float'という形式を追加することもできますが、必ずしも必要ではありません。 – neits
ああ、そうです。 'float'または' integer'リソースを使い、 'dimen'ではなく、それを使ってみてください。 – CommonsWare