0

I am aware that I can't use ListView inside ScrollView, because ScrollView gets the focus in that case and ListView becomes non-scrollable. But I have a program that enables the scrolling of both ListView and ScrollView.(followed the great answer by Mr. Arshu)

Structure of my activity_main.xml

<RelativeLayout    >

<ScrollView 
    android:fillViewport="true"  >

    <LinearLayout   >

        <TextView />

        <TextView  />

        <LinearLayout   >

            <Button
                android:id="@+id/button1"   />

            <Button
                android:id="@+id/button2"   />

        </LinearLayout>

        <RelativeLayout 
            android:visibility="gone"  >

            <WebView />

            <ImageView   />

        </RelativeLayout>

        <LinearLayout   >

            <TextView  />

            <TextView />

            <TextView />

            <TextView />
            
        </LinearLayout>
    </LinearLayout>
</ScrollView> 

<LinearLayout 
    android:layout_alignParentBottom="true" >

    <ImageView />

    <Button />

    <ListView
        android:visibility="gone"  />
</LinearLayout>

</RelativeLayout>

This works perfectly when it is in portrait mode.Each View in Activity has its own purpose.

But I have two issues in Landscape mode. [I can't use activity-land as because I'm playing video in WebView]

  1. The ListView is visible when I click the button.

In portrait mode it display all items(ex: 10). When I change the mode to landscape the ListView doesn't scroll completely and it displays only 5 or 5 1/2 items.

2.WebView visibility is enabled on Button click.

If suppose I enable the webview in portrait mode and video starts playing, and in between if I change the mode to Landscape then the WebView disappears but video is not stopped. I can hear the video.

I've tried to control the view by using savedInstanceState.

Code snippet:

button1.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View view)
    {
        if(savedInstanceState==null)
        {
            String uriPath = "http://player.vimeo.com/***/****";
            Layout.setVisibility(View.VISIBLE);
            myWebView.setWebViewClient(new WebViewClient());
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.loadUrl(uriPath);
        }else {
            Layout.setVisibility(View.VISIBLE);
            myWebView.restoreState(savedInstanceState);
        }
    }
});

Images of ListView:

In portrait:

enter image description here

In landscape:

enter image description here

How to solve these two issues.

Kindly help.

Thank you.

Community
  • 1
  • 1
Prabs
  • 4,923
  • 6
  • 38
  • 59

2 Answers2

1

how about u handle the orientation changes on ur own I mean android:configChanges="keyboardHidden|orientation|screenSize" add the above attribute to Activity tag in Manifest file.

Prabs
  • 4,923
  • 6
  • 38
  • 59
kevz
  • 2,727
  • 14
  • 39
0

I hope this touch listener for your view helps to solve your problem.

Yourview.setOnTouchListener(new OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside
        // ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Disallow the touch request for parent scroll on touch of
            // child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
Nanda
  • 31
  • 3