Android XMLレイアウトの問題
-
24-10-2019 - |
質問
私はすでにこれに何時間も費やしました、それはレイアウトの問題です。誰かが同じアクティビティで画像とビュースイッチャーの両方を表示する方法を教えてもらえますか。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/rg.client.muscle"
android:layout_width="fill_parent"
android:layout_height="fil_parent">
<ViewSwitcher
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<!-- contains two relative layouts of same sizes
containing same elements just with switched positions -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<com.admob.android.ads.AdView
android:id="@+id/adv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:refreshInterval="30" >
</com.admob.android.ads.AdView>
<LinearLayout
android:id="@+id/linear"
android:orientation="horizontal"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/adv" >
<Button
android:id="@+id/but_prev2"
android:text="Previous"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30" >
</Button>
<Button
android:id="@+id/but_more2"
android:text="More"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40" >
</Button>
<Button
android:id="@+id/but_next2"
android:text="Next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30">
</Button>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:id="@+id/linear2"
android:orientation="horizontal"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/but_prev"
android:text="Previous"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30">
</Button>
<Button
android:id="@+id/but_more"
android:text="More"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40">
</Button>
<Button
android:id="@+id/but_next"
android:text="Next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30">
</Button>
</LinearLayout>
<com.admob.android.ads.AdView
android:id="@+id/adv2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/linear2"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:refreshInterval="30">
</com.admob.android.ads.AdView>
</RelativeLayout>
</ViewSwitcher>
<ImageView
android:id="@+id/image"
android:layout_above="@id/relative"
android:padding="2pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</ImageView>
</RelativeLayout>
ImageViewを最初に置くと、新しい画像がロードされるたびにボタンが消え、レイアウト全体が再膨張しているようです
アップデート:
レイアウトには、上部に画像ビューが表示され、ビュースイッチャーが必要です。
解決
XMLを読むことができないことと関係があると思います。それがあなたが元々ここでそれを貼り付けた方法のように見えるなら、それはそれです。最初の問題は、サイズを指定するルートrelativeLayoutタグに何もないことです。あなたのルートレイアウトは、ほとんどの場合、 layout_width
の fill_parent
, 、同じ layout_height
. 。また、スキーマ仕様も必要です(つまり、 xmlns:android="http://schemas.android.com/apk/res/android"
私はあなたがそれを除外しただけだと思っていますが、あなたは実際にそれをコンパイルしているからです。
また、ほとんどすべてが wrap_content
高さの場合、画面の高さを超えた場合、その一部は表示されないため、内側の部分をに包むことを検討することができます。 ScrollView
.
編集:繰り返しますが、私はあなたのrelativeLayout(ルート要素)を設定することをお勧めします fill_parent
. 。最初にImageViewを定義して、残してみてください alignParentTop="true"
, 、次にあなたのビュースイッチャーを定義し、それに与えます layout_below="@id/image"
属性。
他のヒント
そして、小さなアドバイス、使用にはレイアウトが含まれますが、より明確になります。
<include layout="@layout/my_other_layout" />