0

I have a vertical big image, I want to make it scrollable. I've made it like this,

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/logoimage"
            android:scrollbarAlwaysDrawVerticalTrack="true" >

        <ImageView
            android:contentDescription="Specs"
            android:adjustViewBounds="true"
            android:id="@+id/imageScroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:src="@drawable/rules" >
        </ImageView>
        </ScrollView>

But it doesn't work it shows in layout good, but it doesn't display when I start the activity

<RelativeLayout
        android:id="@+id/linear1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#172027"
        android:orientation="horizontal"
        android:visibility="visible">
        <ImageView
            android:layout_width="@dimen/logoSize"
            android:layout_height="@dimen/logoSizeH"
            android:src="@drawable/logocopy"
            android:layout_marginTop="25dp"
            android:id="@+id/logoimage"
            android:layout_marginLeft="20dp"/>
        <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="wrap_content"
            android:layout_below="@+id/logoimage"
            android:background="@drawable/rules"
            android:scrollbarAlwaysDrawVerticalTrack="true" >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ImageView
                    android:adjustViewBounds="true"
                    android:id="@+id/imageScroll"
                    android:layout_width="match_parent"
                    android:fillViewport="true"
                    android:layout_height="wrap_content"
                    android:scrollbars="vertical"
                    android:src="@drawable/rules"
                    android:scaleType="centerCrop" >
                </ImageView>

            </LinearLayout>
        </ScrollView>




        <RelativeLayout
            android:id="@+id/humburger_main1"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_marginTop="30dp"
            android:layout_marginRight="20dp"
            android:layout_alignParentEnd="true"
            android:gravity="center"
            android:orientation="vertical"
            android:layout_alignParentRight="true">

            <LinearLayout
                android:id="@+id/humburger_31"
                android:layout_width="30dp"
                android:layout_height="5dp"
                android:background="#ffff"
                android:orientation="horizontal" />


            <LinearLayout
                android:id="@+id/humburger_11"
                android:layout_width="30dp"
                android:layout_height="5dp"
                android:layout_below="@+id/humburger_31"
                android:layout_marginTop="10dp"
                android:background="#ffff"
                android:orientation="horizontal" />

            <LinearLayout
                android:id="@+id/humburger_21"
                android:layout_width="30dp"
                android:layout_height="5dp"
                android:layout_below="@+id/humburger_31"
                android:layout_marginTop="10dp"
                android:background="#ffff"
                android:orientation="horizontal" />

            <LinearLayout
                android:id="@+id/humburger_41"
                android:layout_width="30dp"
                android:layout_height="5dp"
                android:layout_below="@+id/humburger_21"
                android:layout_marginTop="10dp"
                android:background="#ffff"
                android:orientation="horizontal" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RelativeLayout>
        <LinearLayout
            android:id="@+id/RecyclerView1"
            android:layout_width="20dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:background="#00ff0000"
            android:orientation="horizontal"
            android:scrollbars="vertical">

        </LinearLayout>

    </RelativeLayout>

here's the xml code that is in the activity is scrolls but image does not display

Vladimir
  • 28
  • 1
  • 13

4 Answers4

0

Try this (this code is from an Activity, which has a xml file on the backend containing an ImageView called 'img')

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img"
android:scaleType="center"
android:background="#fff"
android:src="@drawable/picName"
/>
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
Rikin Prajapati
  • 1,913
  • 2
  • 16
  • 23
0

Try to change ImageView code like this:

<ImageView
        android:contentDescription="Specs"
        android:adjustViewBounds="true"
        android:id="@+id/imageScroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:src="@drawable/rules"
        android:scaleType="fitXY" >

Update 1

Alternatively maybe you can try something like this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/logoimage">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp">

        <ImageView
            android:contentDescription="Specs"
            android:adjustViewBounds="true"
            android:id="@+id/imageScroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/rules"
            android:layout_marginTop="0dp" >
        </ImageView>
    </LinearLayout>
</ScrollView>

Update 2

I'm not sure it will work, but try to change your layout to this below:

<RelativeLayout
    android:id="@+id/linear1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#172027"
    android:visibility="visible">
    <ImageView
        android:layout_width="@dimen/logoSize"
        android:layout_height="@dimen/logoSizeH"
        android:src="@drawable/logocopy"
        android:layout_marginTop="25dp"
        android:layout_alignParentTop="true"
        android:id="@+id/logoimage"
        android:layout_marginLeft="20dp"/>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/logoimage"
        android:background="@drawable/rules"
        android:scrollbarAlwaysDrawVerticalTrack="true" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:adjustViewBounds="true"
                android:id="@+id/imageScroll"
                android:layout_width="match_parent"
                android:fillViewport="true"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"
                android:src="@drawable/rules"
                android:scaleType="center" >
            </ImageView>

        </LinearLayout>
    </ScrollView>

    <RelativeLayout
        android:id="@+id/humburger_main1"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_marginTop="30dp"
        android:layout_marginRight="20dp"
        android:layout_alignParentEnd="true"
        android:gravity="center"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/scrollview">

        <LinearLayout
            android:id="@+id/humburger_31"
            android:layout_width="30dp"
            android:layout_height="5dp"
            android:background="#ffff"
            android:orientation="horizontal" />

        <LinearLayout
            android:id="@+id/humburger_11"
            android:layout_width="30dp"
            android:layout_height="5dp"
            android:layout_below="@+id/humburger_31"
            android:layout_marginTop="10dp"
            android:background="#ffff"
            android:orientation="horizontal" />

        <LinearLayout
            android:id="@+id/humburger_21"
            android:layout_width="30dp"
            android:layout_height="5dp"
            android:layout_below="@+id/humburger_31"
            android:layout_marginTop="10dp"
            android:background="#ffff"
            android:orientation="horizontal" />

        <LinearLayout
            android:id="@+id/humburger_41"
            android:layout_width="30dp"
            android:layout_height="5dp"
            android:layout_below="@+id/humburger_21"
            android:layout_marginTop="10dp"
            android:background="#ffff"
            android:orientation="horizontal" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/RecyclerView1"
        android:layout_width="20dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android_layout_toRightOf="@id/scrollview"
        android:background="#00ff0000"
        android:orientation="horizontal"
        android:scrollbars="vertical">

    </LinearLayout>

</RelativeLayout>
Valentino
  • 2,125
  • 1
  • 19
  • 26
0

sorry but did u set this layout in your activity? use this simple layout instead of yours.

 <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

 </ScrollView>
Mehran Zamani
  • 831
  • 9
  • 31
0

i searched so long for this issue and finally find this code:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img"
    android:scaleType="center"
    android:background="#fff"
    android:src="@drawable/picName"/>

and also this

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.xml_name_layout);

    final ImageView switcherView = (ImageView)this.findViewById(R.id.img);

    switcherView.setOnTouchListener(new View.OnTouchListener()
    {

        public boolean onTouch(View arg0, MotionEvent event)
        {

            float curX, curY;

            switch (event.getAction())
            {

                case MotionEvent.ACTION_DOWN:
                    mx = event.getX();
                    my = event.getY();
                    break;
                case MotionEvent.ACTION_MOVE:
                    curX = event.getX();
                    curY = event.getY();
                    switcherView.scrollBy((int) (mx - curX), (int) (my - curY));
                    mx = curX;
                    my = curY;
                    break;
                case MotionEvent.ACTION_UP:
                    curX = event.getX();
                    curY = event.getY();
                    switcherView.scrollBy((int) (mx - curX), (int) (my - curY));
                    break;
            }

            return true;
       }
    });
}

did the job perfectly for me... horizontal & vertical scrolling included (enabled)

Mehran Zamani
  • 831
  • 9
  • 31
SamiAzar
  • 1,260
  • 13
  • 29