1

I'd like to have a text field and a scrollable (that contains a drawable) in an application. I'd like the textview to stay anchored to the screen as I scroll. I already have the drawview being rendered in the scrollview with this code in my activity file:

        drawView = new DrawView(this, height, width, SMD);
            drawView.setBackgroundColor(Color.WHITE);
            ScrollView scrollView = new ScrollView(this);
            scrollView.addView(drawView);
            setContentView(scrollView);

I saw this page:

Android: How do I add a footer to a fullscreen scrollview?

To prevent you from having to follow the link they suggest a Manifest entry such as:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TableRow><TextView android:text="Text1"/></TableRow>
            <TableRow><TextView android:text="Text2"/></TableRow>
        </TableLayout>
        <RelativeLayout 
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView 
                android:text="@string/lorem_ipsum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </RelativeLayout>
        <LinearLayout 
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
                android:text="Text3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:text="Text4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Reading that page I thought I could employ the Manifest changes listed in the above hyperlink along with this modified code:

        drawView = new DrawView(this, height, width, SMD);
            drawView.setBackgroundColor(Color.WHITE);
            ScrollView scrollView = new ScrollView(this);
            scrollView.addView(drawView);
            setContentView(scrollView);
            TextView tv = new TextView(this);
            tv.setText("Hellow World Im running with no issue");
            setContentView(tv);

to obtain what I want. However the screen only renders the scrollview or the TextView (depending on which one is called last). Do I realy need to make the Manifest changes as noted in the other answer? I do not list any objects such as ScrollViews in my current manifest, but I cannot imagine that causes a problem. Listing them now should simply define HOW they behave with the other objects, correct?

Community
  • 1
  • 1
WildBill
  • 9,143
  • 15
  • 63
  • 87
  • 1
    You got me confused.. It is a layout xml not a manifest dude.. The manifest presents essential information about the application to the Android system. – Shankari vatsalkumar Jul 29 '13 at 04:56
  • No doubt I'M confused. Do I NEED to use the Manifest to accomplish what I want to do? The only reason I think I needed to use the Manifest was because of the other stackoverflow question... – WildBill Jul 29 '13 at 05:13

3 Answers3

2

What you are referring to as a manifest is actually a layout file(as pointed out by Shanku). Your project can contain any number of layout files, but only one manifest is required and allowed. You can read on what, why and where of AndroidManifest.xml here: The AndroidManifest.xml file.

Try this xml code to get a stationary TextView footer with a ScrollView above it:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout 
        android:id="@+id/linear_layout_for_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/black"
        android:layout_alignParentBottom="true" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Some Text"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linear_layout_for_text"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

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

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/some_pic" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/another_pic" />

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

You can add however many ImageViews to the scrolling container. In the code above, I have added two. This produces the following result:

When the Activity starts:

enter image description here

After the user scrolls a bit vertically

enter image description here

Vikram
  • 51,313
  • 11
  • 93
  • 122
  • You and Shanku both had good, correct answers. I chose yours as it helped explain the layout file (didn't realize that existed) and why this is not done in a Manifest file. – WildBill Aug 12 '13 at 00:27
1

No, you dont need to change xml layout.. you can dynamically create one..

Your second setContentView removes the first one, which is why you only have testview or ScrollView..To do what you want you need to add a container with setContentView that can itself hold more than one View.

One such container is a LinearLayout. You will have to create it, set its orientation to Horizontal, and add both TextView:

drawView = new DrawView(this, height, width, SMD);
drawView.setBackgroundColor(Color.WHITE);
ScrollView scrollView = new ScrollView(this);
scrollView.addView(drawView);
//  setContentView(scrollView);
TextView tv = new TextView(this);
tv.setText("Hellow World Im running with no issue");
// setContentView(tv);  

LinearLayout linear = new LinearLayout(this);
// Not necessary as it's the default but useful to know
linear.setOrientation(LinearLayout.HORIZONTAL); 
linear.addView(scrollView);
linear.addView(tv);


//set the text view as the activity layout
setContentView(linear);

Hope this helps!!

0
<LinearLayout>
      <LinearLayout>
            <TextView />
      </LinearLayout>
      <ScrollView>
           // Whatever you want to be scrolled put it here
      </ScrollView>
</LinearLayout>

If you want to dynamically add view to scrollview, you can use scrollview's Id and do scrollview.addView for that..

Vedang Jadhav
  • 510
  • 2
  • 11