0

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.

enter image description here

7
  • 3
    +1000 Nice background. Commented Aug 16, 2013 at 10:18
  • So you want the green area to scroll with the black area always at the bottom of the screen? Commented Aug 16, 2013 at 10:21
  • @user2145222 Thanks. The black area does not scroll with scroll. The black area is under the scroll view. Commented Aug 16, 2013 at 10:25
  • "I want to wrap this text views (I have another views as well) using scroll view." What is exactly you want? could you clarify it? Commented Aug 16, 2013 at 10:29
  • @hieuxit I meant I have few views that I want to put to the scroll view but using relative layout. Under scroll view I want to have another view. Commented Aug 16, 2013 at 10:35

2 Answers 2

3

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.

<?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?

Sign up to request clarification or add additional context in comments.

1 Comment

And if you want have another space for the first view using marginTop. you should you <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30dip" android:text="Calculation" /> do not use in the parent LinearLayout
0

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>       

2 Comments

thanks for answer but as I think this parameters from my code will not work. I mean about android:layout_marginTop="30dp" etc
@Matrosov Alexander I am confused, adding the line 'android:layout_marginTop="30dp"' to the linearlayout named 'mainbody' works fine. You can also add it to the scrollview itself if you wish as it is inside a relative layout in my example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.