Lack of scrolling effect with ScrollView in PopupWindow

I want to implement a pop-up menu with complex effects, one of which is scroll support. It looks like PopupMenu and AlertDialog cannot satisfy the requirements that I need. So I tried PopupWindow with ScrollView.

First, I prepared a layout that has a simple structure just like ApiDemo shows:

ScrollView LinearLayout with Vertical attribute TextView TextView TextView ... 

Secondly, I create a PopupWindow with this layout and 200width / 300height, showing it somewhere with showAtLocation ().

I can do a scroll display and have a scroll effect, but the TextViews in LinearLayout DO NOT scroll (they are in a fixed position)!

Something is wrong, but I have no meaning. (Android3.0)

Thanks for any warmhearted person who can give me some advice.

-_- !!

+6
source share
2 answers

I also ran into a similar problem. Some, like wrapping a relative layout in scrollview does not work for popupwindow.

I tried wrapping individual views under scrollview, and it worked for me. PLease see below. Hope this helps

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#eebd9c" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" > <ScrollView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_below="@+id/textView2" > <TextView android:id="@+id/textView9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:ems="15" android:gravity="fill_horizontal" android:minLines="6" android:scrollbars="vertical" android:singleLine="false" android:text="Multiline text" android:textAppearance="?android:attr/textAppearanceSmall" /> </ScrollView></RelativeLayout> 
+2
source

I think your requirement can be filled by Dialog, try the code I gave

 protected void showInputDialog() { final Dialog splRerDialog = new Dialog(getContext()); splRerDialog.setTitle("Special request."); ScrollView scroll = new ScrollView(getContext()); LinearLayout lin = new LinearLayout(getContext()); lin.setLayoutParams( new LayoutParams(350,200)); lin.setGravity(Gravity.CENTER); lin.setOrientation(LinearLayout.VERTICAL); final EditText req = new EditText(getContext()); req.setLayoutParams( new LayoutParams(300,300)); lin.addView(req); Button btn = new Button(getContext()); btn.setText("Ok"); btn.setLayoutParams( new LayoutParams(200,LayoutParams.WRAP_CONTENT)); btn.setGravity(Gravity.CENTER); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { splRerDialog.dismiss(); } }); lin.addView(btn); scroll.addView(lin); splRerDialog.addContentView(scroll, new LayoutParams(LayoutParams.WRAP_CONTENT,200)); splRerDialog.show(); } 
0
source

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


All Articles