2016-10-20 16 views
0

Scrollviewを使用しない場合、ボタンが画面の下部に表示されます。しかし、Scrollviewを追加するとすぐに、ボタンは画面の最下部に表示されません。ボタンが最下部にある必要があります

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/create_account_view"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:id="@+id/scrollview_wrapper" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_marginTop="0dp" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:layout_marginBottom="10dp" 
       android:lines="1" 
       android:gravity="center" 
       android:textSize="16sp"/> 

     </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

なぜScrollViewを使用しているのですか?それ以上の要素はありますか? – vidulaJ

+0

'RelativeLayout'の幅は' ScrollView'の内部にあるので、 'wrap_content'でオーバーライドされます。 – MohanadMohie

+0

ボタンをスクロールビューの外に置きます。 – james

答えて

1

ScrollViewに別の属性を追加します。

android:fillViewport="true" 

この道をScrollView高さは、子供のandroid:layout_height="match_parent"属性を尊重し

+0

もちろん、ボタンの高さが「ラップコンテンツ」の代わりに伸びています –

+0

本当ですか? 'RelativeLayout'の' android:layout_height'属性は 'match_parent'に設定され、' Button'の 'android:layout_height'属性は' wrap_content'に設定されていますか?私はあなたのレイアウトをこのパラメータでテストしたところ、うまくいきました。 –

+0

あなたが正しいです、私はアンドロイドを使用していました:layout_below。しかし、キーボードが現れると、スクロールビューは画面の高さからキーボードを差し引いた高さなので、ボタンが上になります。私はそれを望んでいない、あなたはそれのための解決策を持っている? –

0

この

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/create_account_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/button1"> 


</ScrollView> 


<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="10dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_marginTop="0dp" 
    android:gravity="center" 
    android:lines="1" 
    android:textSize="16sp" /> 

</RelativeLayout> 
0

を試す問題は、スクロールビューにある、ちょうどあなたのスクロールビューに次の属性を追加します。

android:fillViewport="true" 
0

を単にスクロールビューに

app:layout_behavior = "@string/appbar_scrolling_view_behavior" 

をスクロールビューの動作を追加ボタンxにコードを追加しますmlファイル

android:layout_alignParentBottom = "true" 
android:layout_centerHorizontal = "true" 
関連する問題