次のレイアウトファイルがあります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/blue" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/red" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/yellow" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/blue" />
</LinearLayout>
ネストされた重みを使用しており、パフォーマンスの問題を認識しています。
このレイアウトをアプリウィジェットに表示したいのですが、アプリウィジェットをロードすると、「ウィジェットをロードできませんでした」というメッセージが表示されます。これは、ネストされた重みが原因だと思います(わかりません)。
基本レイアウトにを使用するRelativeLayout
と、次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/blue" />
<View
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/blue" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom"
android:layout_below="@id/top" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/red" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/yellow" />
</LinearLayout>
</RelativeLayout>
このレイアウトを使用すると、赤と黄色のビューが表示されません。高さはにとどまっていると思います0dp
。
どうすれば目標を達成できますか?
明確にするために:私は上下の固定高さでビューを表示したいと思います。それらの間に、ギャップを埋めて、同じ高さのビューをいくつか表示したいと思います。
編集
だから私は何かを見つけました。レイアウトに2つのレベルのViewGroupがある場合、appwidgetは次のように表示されません。
<LinearLayout
android:id="@+id/middle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >
</LinearLayout>
<View
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:background="@color/teal" />
<View
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:background="@color/teal" />
これは機能しますが、機能しません。
<LinearLayout
android:id="@+id/middle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red" />
</LinearLayout>
<View
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:background="@color/teal" />
<View
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:background="@color/teal" />
なぜこれが起こるのか、そして私のアイデアを実装する方法を誰かが知っていますか?クリストファーの画像は私の考えを示しています。