user3320657
user3320657

Reputation:

Scrollview not working even after adding only one child to it

I just wonder why my view is not scrollable. As told by the following links:

How to make a LinearLayout scrollable

Making LinearLayout Scrollable

I've got my linear layout within the scrollview and there is only one child for the scroll view. Still my view is not scrollable. Could someone tell me why it is not working.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.tdg.nottssports.FirstActivity" >

    <LinearLayout
        android:id="@+id/linearContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

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

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Contact" />

            <EditText
                android:id="@+id/etContact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="hello world" >
            </EditText>
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Telephone" />

            <EditText
                android:id="@+id/etTelephone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="phone"
                android:text="07424063798" 
                android:singleLine="true"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true">
            </EditText>
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView41"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Address Line 1" />

            <EditText
                android:id="@+id/etAddrLine1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:text="hello world"
                android:singleLine="true"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true" >
            </EditText>
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView42"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Address Line 2" />

            <EditText
                android:id="@+id/etAddrLine2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:text="hello world" 
                android:singleLine="true"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true">
            </EditText>
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView43"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Town" />

            <EditText
                android:id="@+id/etTown"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:text="hello world" 
                android:singleLine="true"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true">
            </EditText>
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView44"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="PostCode" />

            <EditText
                android:id="@+id/etPostCode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:text="hello world"
                android:singleLine="true"
                android:lines="1"
                android:maxLines="1"
                android:scrollHorizontally="true" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView144"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date of Visit" />

            <EditText
                android:id="@+id/etDateVisit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:text="" />
        </LinearLayout>

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

            <Button
                android:id="@+id/btnNext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Next" />
        </LinearLayout>

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

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

</ScrollView>

I accidentally missed the following portion in my question.

I've got the following code in Activity.java where I add images dynamically to the LinearLayout with the help of ImageView.

LinearLayout linearContainer = (LinearLayout) findViewById(R.id.linearContainer);

ImageView imageViews = new LinearLayout(getApplicationContext());

linearContainer.addView(imageViews);

btnAddImage.setOnClickListener() {
    ImageView image = new ImageView(getApplicationContext());
    image.setImageBitmap(myBitmap);
    imageViews.addView(image);
    image.setPadding(10, 10, 10, 10);
}

Does the above create any problem to scrolling? If yes, kindly help me out how to make it work.

Upvotes: 1

Views: 577

Answers (2)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

Try using this way:

android:orientation="vertical"

Or an another way is:

<RelativeLayout
    android:id="@+id/ButtonLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom" >

    <Button
        android:id="@+id/add_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10sp"
        android:onClick="editItem"
        android:layout_alignParentBottom="true"
        android:text="@string/button_edit" />
</RelativeLayout>

Upvotes: 0

Nirav Tukadiya
Nirav Tukadiya

Reputation: 3417

set fillViewPort property of scrollview to true.it should work then after.hope it will help.

Upvotes: 1

Related Questions