2015-10-19 97 views
0

我正在设计一个移动设备(android)的屏幕,我想在屏幕上显示多个文本框和按钮。如何创建滚动布局

有人请指导我如何使我的屏幕滚动能够使所有的文本框和按钮可以在同一页上创建和查看。

我试过寻找不同的帖子也试图找到任何财产,但无法取得成功。

问候, 古尔

回答

0

使用ScrollView。当他的ScrollView的内容不符合分配的高度时,它将变成可滚动的。

注意 ScrollView只能包含一个直接的子元素,所以如果您需要多个东西可滚动,您需要将该内容包装到布局中。

下面是一个例子

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

     <TextView 
       android:id="@+id/tv_long" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:text="@string/really_long_string" > 
     </TextView> 

     <Button 
       android:id="@+id/btn_act" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="View" > 
     </Button> 
    </LinearLayout> 
</ScrollView> 

enter image description here

0

使用滚动型为主体的父布局。如果您不提供滚动视图,则无法滚动页面。

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

    <LinearLayout 

     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 1" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 2" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 3" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 4" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 5" /> 

     <ProgressBar 
      android:id="@+id/progressBar1" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <RadioButton 
      android:id="@+id/radioButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RadioButton 1" /> 

     <RadioButton 
      android:id="@+id/radioButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RadioButton 2" /> 

     <ToggleButton 
      android:id="@+id/toggleButton1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="ToggleButton" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 6" /> 

     <SeekBar 
      android:id="@+id/seekBar1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 7" /> 

     <Button 
      android:id="@+id/button4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 8" /> 

     <CheckBox 
      android:id="@+id/checkBox1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="CheckBox" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 9" /> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 10" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Button 11" /> 
    </LinearLayout> 

</ScrollView>