2016-08-11 4 views
0

質問がありました。回答が見つかりませんでした。 レイアウトをスクロールしてスクロールしない別のレイアウトを作成するにはどうすればよいですか? 一方、私はレイアウトを作る必要がある場合はスクロールするいくつかのボタンを含め、私は画面の下部に2つのボタンを配置したいと私はそれらがスクロールするときに消えたくない。アクティビティの一部をスクロールする方法

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="@drawable/background" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:context="com.myname.myapp.MainActivity"> 

    // a bunch of Buttons and TextViews 

    </RelativeLayout> 
</scrollView> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

     // two Moveless Buttons 

</RelativeLayout> 

しかし、動作しません。

+0

「機能しません」とはどういう意味ですか?あなたはこのアプリを実行し、どのようにあなたが望むものと異なるのでしょうか? –

+0

エラーがあります。 "Multiple Root Tags" – Skillson

+0

グーグルのエラーメッセージはほとんど常に良い結果をもたらします。たとえば、[this](http://stackoverflow.com/questions/24275533/multiple-root-tags-in-android-studio)。 –

答えて

3

ScrollViewの幅と高さは、親と同じです。つまり、使用可能な領域全体を占有し、RelativeLayoutには何も残しません。おそらく、すでに持っているものをLinearLayoutの中にラップし、layout_weight属性を使ってスペースを分割したいと思うでしょう。

+0

はい。できます。どうもありがとう。ありがとう。 – Skillson

0

あなたは何をしたいのか分かりません。しかし、あなたのルートscrollviewとの垂直のLinearLayoutを行い、スクロール可能なビューを保持するために、そしてRelativeLayout、自分のボタンを保持するために

  <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
       > 
     <ScrollView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:background="@drawable/background" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        tools:context="com.myname.myapp.MainActivity"> 

       // a bunch of Buttons an TextViews 


       </RelativeLayout> 
      </ScrollView> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="80dp (for example)>" 
        android:layout_alignParentBottom="true"> 

        // two Moveless Buttons 

      </RelativeLayout> 
</RelativeLayout> 
+0

あなたのソリューションは動作します。まさに私が望むもの。 – Skillson

0

(コード例のAndroid Studioでテストされていない)、これを試してみて、フィードバックに

を与えます。

LinearLayoutの重み付け機能を利用するには、Scrollviewに1のウェイトを適用します。これにより、ボタンを押さえたままのRelativeLayoutが最大のボタンのサイズになります。ここで

は一例です:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ScrollView 
     android:background="@drawable/background" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      tools:context="com.myname.myapp.MainActivity"> 

     // a bunch of Buttons an TextViews 

     </RelativeLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

      // two Moveless Buttons 

    </RelativeLayout> 
</LinearLayout> 

HTHS!

関連する問題