Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android滚动视图弹出窗口不工作_Android_Xml_Android Studio_Scrollview - Fatal编程技术网

Android滚动视图弹出窗口不工作

Android滚动视图弹出窗口不工作,android,xml,android-studio,scrollview,Android,Xml,Android Studio,Scrollview,我是android的新手。我正在尝试在android上实现可滚动的弹出窗口 如果在我的视图中创建滚动视图,则其显示错误ScrollView只能承载一个直接子级(详细信息) 这是我的密码 private PopupWindow pwindo; private void initiatePopupWindow() { try { // We need to get the instance of the LayoutInflater Layou

我是android的新手。我正在尝试在android上实现可滚动的弹出窗口

如果在我的视图中创建滚动视图,则其显示错误ScrollView只能承载一个直接子级(详细信息)

这是我的密码

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

        }
    };
我的看法呢

<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  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>

. . . .

在下面,您应该这样做

<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>

在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>
这可能会帮助你

<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>
>
.
.
.
.

将LinearLayout添加为直接子项,并将其他控件放入其中。

ScrollView
正在使用
PopupWindow

我的问题是因为弹出窗口的窗口高度没有限制


您可以通过方法
View.measure(int-widthMeasureSpec,int-heightMeasureSpec)
预先确定布局的高度,但它不应该是无限的,并且高度小于屏幕或窗口,然后将作为父级滚动。将scrollview高度设置为wrap_content.no,scrollview必须只包含一个直接子级,因此LinearLayout应该位于内部ScrollView@Kaushik我试过了,兄弟。。但这对我也没有帮助。。。!!那么,请更新您的问题…您所尝试的ScrollView只能承载一个直接子级。如果您使用我的解决方案,请尝试向ScrollView添加父级布局(主要是Linearlayout),并将ID(@+ID/popup_元素)分配给该父级布局,而不是将ID分配给ScrollView,则不会出现此错误。并确保ScrollView只包含一个子布局。因此,将您的其他布局合并为单线布局,并将该布局作为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:id="@+id/child">
    <TextView/>
    <TextView/>
    <TextView/>
    <ImageButton/>
    <ImageButton/>
  .
  .
  .
  .

 </LinearLayout>
 </ScrollView>