2011-10-19 26 views
0

画像が背景として塗りつぶされた画面と、画像上に浮かぶ3つのボタンが必要です。私はxmlでこの罰金を作成し、それは私が望むことを垂直方向で行います。しかし、私はスクロールビューを追加しようとしており、これらの要素を正しく組み合わせる方法については非常に混乱しています。様々な試みの後、私は背景画像と浮動ボタンのスクロール

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView android:layout_height="fill_parent" 
android:layout_width="fill_parent" android:id="@+id/home_container" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<ImageView android:src="@drawable/alert" 
    android:layout_height="fill_parent" android:layout_width="fill_parent" 
    android:scaleType="fitCenter" android:clickable="true" 
    android:enabled="true" /> 
<LinearLayout android:layout_width="fill_parent" 
    android:paddingBottom="25px" android:paddingLeft="25px" 
    android:orientation="vertical" android:paddingTop="90px"  android:id="@+id/toplinear" 
    android:layout_height="fill_parent" android:paddingRight="25px" 
    android:gravity="top"> 
    <Button android:layout_width="fill_parent" android:textSize="20dp" 
     android:id="@+id/startprogrambutton" android:paddingBottom="12dp" 
     android:text="@string/text1" android:layout_height="wrap_content" 
     android:paddingTop="12dp"></Button> 
    <Button android:layout_width="fill_parent" android:textSize="20dp" 
     android:id="@+id/button1" android:paddingBottom="12dp" 
     android:layout_marginTop="10dp" android:background="@drawable/webview_buttons" 
     android:text="@string/text2" android:layout_height="wrap_content" 
     android:paddingTop="12dp"></Button> 
    <Button android:layout_width="fill_parent" android:textSize="20dp" 
     android:id="@+id/button2" android:paddingBottom="12dp" 
     android:layout_marginTop="10dp" android:background="@drawable/webview_buttons" 
     android:text="@string/text3" android:layout_height="wrap_content" 
     android:paddingTop="12dp"></Button> 
    <Button android:layout_width="fill_parent" android:textSize="20dp" 
     android:id="@+id/button3" android:paddingBottom="12dp" 
     android:layout_marginTop="10dp" android:background="@drawable/webview_buttons" 
     android:text="@string/text4" android:layout_height="wrap_content" 
     android:paddingTop="12dp"></Button> 
</LinearLayout> 

、以下に示すステージは今scrollviewとエラーが唯一の子を含めることができ、それに達しました。再配置する方法はありますか?私は自分のイメージとフローティングボタンを一緒にスクロールすることができますか?

答えて

0

ImageViewLinearLayoutを別のVerticalに入れてください。LinearLayoutこれはあなたのscrollView子の問題を解決します。

<ScrollView> 
<LinearLayout> 
<Imageview /> 
<LinearLayout /> 
</LinearLayout> 
</ScrollView> 

あなたはボタン付きのLinearLayoutの背景として画像を与えていないのはなぜ、それがあなたの目的を果たすだろう。

+0

それはerrorring停止しますが、今の画像は背景が、ボタンの上の別々の要素ではありません。ここに公式ドキュメントを参照してください。スクロールしなくてもOKだったときは、フレームレイアウトのすべてを持っていたことを忘れてしまった。私が理解しているように、スクロールビューはフレームレイアウトです。 – ron

+0

ボタンを使用した線形レイアウトには、android:background = "@ drawable/alert"属性を使用します。 imageViewを削除します。 、はい、それをframeLayoutに置き換えることもできます。そのフレームをスクロールビューの内側に配置します。 –

+0

ありがとうYashwanth - 背景attr didiそれ。 – ron

0

あなただけのボタンやないImageViewのをスクロールしたい場合、あなたはこれを試すことができます。

<LinearLayout> 
    <Imageview /> 
    <ScrollView> 
     <LinearLayout> 
      <Button /> 
      <Button /> 
      <Button /> 
      <Button /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

・ホープ、このことができます!

0

あなたが知っているとおり、あなたは両方の向きに対して単一の解決策を見つけることに限定されません。 land &ポートディレクトリに別々のレイアウトxmlファイルを指定することにより、両方の方向に対して2つの別々のレイアウトを持つことができます。

http://developer.android.com/guide/practices/screens_support.html

+1

この参考情報をお寄せいただきありがとうございます – ron

+0

NPロン...アップヴォートでいくつかの愛を見せてどうですか? :O) – SBerg413