Android scroll popup not working

I am new to android. I am trying to implement a scrollable popup on Android.

If I do a scroll view My view displays an error message ScrollView may contain only one direct child element (Details)

here is my code

   private PopupWindow pwindo;

    private void initiatePopupWindow() {
        try {
// We need to get the instance of the LayoutInflater
            LayoutInflater inflater = (LayoutInflater) About.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.screen_popup,
                    (ViewGroup) findViewById(R.id.popup_element));
            pwindo = new PopupWindow(layout,700,1000, true);
           // pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
          //  pwindo.showAsDropDown(layout, 80, 80);

            btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
            btnClosePopup.setOnClickListener(cancel_button_click_listener);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private OnClickListener cancel_button_click_listener = new OnClickListener() {
        public void onClick(View v) {
            pwindo.dismiss();

        }
    };

And my look

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/popup_element">
<TextView/>
<TextView/>
<TextView/>
<ImageButton/>
<ImageButton/>
.
.
.
.


</ScrollView>

Thanks in advance.

+4
source share
4 answers

Take Linear Layout as Parent:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
                   android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"> <ScrollView

    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/popup_element"> <TextView/> <TextView/> <TextView/> <ImageButton/> <ImageButton/> . . . .


</ScrollView> </linearLayout>
+1
source

Here below you should do it this way!

<LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:id="@+id/popup_element">
    <TextView/>
    <TextView/>
    <TextView/>
    <ImageButton/>
    <ImageButton/>
    .
    .
    .
    .


    </ScrollView>
</LinearLayout>
+1
source

LinearLayout ScrollView , ;

:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/popup_element">
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical">
      <TextView/>
      <TextView/>
      <TextView/>
      <ImageButton/>
      <ImageButton/>
   </LinearLayout>

</ScrollView>

Put all of these views inwards LinearLayout and also give a little less width and height for the popup

pwindo = new PopupWindow(layout,400,400, true);
+1
source

It can help you ...

<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/popup_element">>
<LinearLayout
android:id="@+id/child">
    <TextView/>
    <TextView/>
    <TextView/>
    <ImageButton/>
    <ImageButton/>
  .
  .
  .
  .

 </LinearLayout>
 </ScrollView>

Add LinearLayout as a direct child and place other controls in it.

+1
source

Source: https://habr.com/ru/post/1622861/


All Articles