简体   繁体   English

Android设置scrollview与相对布局

[英]Android setup scrollview with relative layout

I have next code: 我有下一个代码:

<TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="30dp"
        android:text="@string/cm_diameter"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/textView3"
        android:layout_marginTop="28dp"
        android:text="@string/from"
        android:textAppearance="?android:attr/textAppearanceSmall" />

The parameters that I am using are connected to relative layout. 我正在使用的参数已连接到相对布局。

I want to wrap this text views (I have another views as well) using scroll view. 我想使用滚动视图包装这些文本视图(我也有另一个视图)。

My image shows the scroll view (green view) and below the scroll view some another container (black view). 我的图像显示滚动视图(绿色视图),在滚动视图下方显示另一个容器(黑色视图)。 How can I achieve this result? 我怎样才能达到这个结果?

I've tried to use liner layout in scroll view but it has different result that I expected. 我曾尝试在滚动视图中使用衬板布局,但结果与预期不同。

在此处输入图片说明

I don't know what exactly android:layout_marginTop you put in. But as your design above I try to make a simple layout for this, and I think it work. 我不知道您输入的是android:layout_marginTop到底是什么。但是当您在上面的设计中,我尝试为此做一个简单的布局,并且我认为它可以工作。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#ff00ff00" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Calculation" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="30dip"
            android:text="Item1"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="30dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dip"
            android:text="Another text view for test"
            android:textAppearance="@android:style/TextAppearance.Large" />
    </LinearLayout>
</ScrollView>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff000000"
    android:padding="20dip" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Add parameter" />
</FrameLayout>

Is it right? 这样对吗?

Hopefully this example will get you started if I have understood you correctly. 希望本示例可以帮助您入门,如果我对您的理解正确的话。 (Apologies if I have not.) (如果没有的话,抱歉。)

  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00ff00"
>
<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:layout_above="@+id/footer" >
    <LinearLayout 
        android:id="@+id/mainbody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"            
        android:orientation="vertical"          
        >           
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Calculation"/>
        <!--Add the rest of you views here possibly changing 'mainbody'
        to be a RelativeLayout depending on the rest of your layout-->          
    </LinearLayout>
</ScrollView>     
<RelativeLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#ff000000"
    android:layout_alignParentBottom="true">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My footer button"
        android:layout_margin="10dip"
        android:layout_centerInParent="true"/>
</RelativeLayout>       

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM