0

我正在尝试对包含滚动视图的视图进行充气,并且在以下行中对视图进行充气时得到 ClassNotFoundException android.view.scrollview:

查看布局 = inflater.inflate(R.layout.news_article, null, true);

我自己找不到任何问题,谷歌搜索这个问题对我没有帮助(不幸的是)。

另一方面,这实际上也是我不知道该怎么做的解决方法。

情况:我有一个带有 3 个选项卡的选项卡布局。在每个选项卡中,我都有一个包含新闻项目的列表视图。当我点击新闻项目时,我希望 listview 布局与我现在用于弹出窗口的 xml 布局进行切换(这有点作弊,但我不知道如何正确地做到这一点)。因此,如果有人有办法做到这一点而不是使用弹出窗口,那对我来说将是最好的答案。

我膨胀布局的方法:

@Override
public void onClick(View v) 
{
   //setContentView(R.layout.news_article);
   final PopupWindow popUp;
   LayoutInflater inflater = (LayoutInflater)NewsActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
   View layout = inflater.inflate(R.layout.news_article, null, false);
   Display display  =GetWindowManager().getDefaultDisplay();
   int popUpWidth = display.getWidth();
   int popUpHeight = display.getHeight();

   popUp = new PopupWindow(layout,  popUpWidth, popUpHeight, true); 
   popUp.setOutsideTouchable(true);                     

   popUp.setTouchInterceptor(new OnTouchListener()
   {
      @Override
      public boolean onTouch(View v, MotionEvent event) 
      {
        System.out.println("Touch Intercepted");
        if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
        { 
             popUp.dismiss();
        }
            return false;
      }
   });

   popUp.showAtLocation(getListView(), Gravity.TOP, 0, 75);
}

布局的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<Scrollview
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/news_article_scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffffff">

    <ImageView
        android:id="@+id/news_article_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:src = "@drawable/ic_launcher"/>

    <TextView
        android:id="@+id/news_article_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:textColor="#000000"
        android:layout_toRightOf="@+id/news_article_icon"
        android:layout_marginTop="10dp"
        android:text="Header" />

    <TextView
        android:id="@+id/news_article_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/news_article_icon"
        android:layout_marginTop="10dp"
        android:textColor="#000000"
        android:text="Text" />

</RelativeLayout>
</Scrollview>

** * ****编辑* ** * **** 好的,弹出窗口现在显示,但我没有收到任何事件

4

2 回答 2

2

我在我的代码中尝试了它,当我在 xml 文件中将 Scrollview 更改为 ScrollView 时它可以工作:

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

</ScrollView>

如果您使用小“v”编写 xml,则该 xml 是正确的,但充气机无法识别它并且需要大写“V”。

当您在它周围放置一个 try catch 块并检查异常时,您可以很容易地看到这一点,因为它在那里说。

于 2012-04-19T22:53:03.643 回答
0

当你膨胀你的布局时,你没有设置 parentView,但你设置了标志true

View layout = inflater.inflate(R.layout.news_article, null, true);

将标志设置为 false 并将视图添加到您需要的位置。

View layout = inflater.inflate(R.layout.news_article, null, false); 
myParentViewGroup.add(layout);
于 2012-04-19T22:49:46.177 回答