2012-01-05 33 views
6

Tôi muốn triển khai thực đơn bật lên có hiệu ứng phức tạp, một trong số đó là hỗ trợ cuộn. Có vẻ như PopupMenu và AlertDialog không thể đáp ứng yêu cầu những gì tôi cần. Vì vậy, tôi đã thử PopupWindow với ScrollView.Không có hiệu ứng cuộn với ScrollView trong PopupWindow

Thứ nhất, tôi đã chuẩn bị một cách bố trí trong đó có một strcture đơn giản giống như những gì ApiDemo cho thấy:

ScrollView 
    LinearLayout with Vertical attribute 
     TextView 
     TextView 
     TextView 
     ... 

secondarily, tôi mới một PopupWindow với cách bố trí này và 200width/300height, hiển thị nó ở đâu đó với showAtLocation() .

Tôi có thể làm cho thanh cuộn hiển thị và có hiệu ứng cuộn, nhưng TextViews trong LinearLayout KHÔNG cuộn (chúng ở vị trí cố định)!

Đã xảy ra sự cố nhưng tôi không có ý thức về điều đó. (android3.0)

Cảm ơn bất kỳ người đàn ông ấm áp nào có thể cho tôi một số mẹo.

-_- !!

Trả lời

0

Tôi nghĩ rằng yêu cầu của bạn có thể được fullfilled bởi Dialog thử đoạn code tôi đã trao

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(); 
    } 
2

Tôi cũng phải đối mặt với vấn đề tương tự. Một số cách bố trí bố cục tương đối trong scrollview không hoạt động với popupwindow.

Tôi đã thử gói từng chế độ xem riêng lẻ dưới chế độ xem cuộn và nó đã hoạt động đối với tôi. Xin hãy xem bên dưới. Hy vọng điều này sẽ giúp

<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> 
Các vấn đề liên quan