打开视图时,ClassNotFoundException android.view.scrollview
我试图膨胀一个包含scrollview的视图,在以下行膨胀视图时,我得到一个ClassNotFoundException android.view.scrollview: 视图布局=充气机。充气(R.layout.news\u article,null,true) 我自己找不到任何错误,谷歌搜索这个问题也帮不了我(不幸的是) 另一方面,这实际上也是我不知道怎么做的一个变通方法 情况: 我有一个包含3个选项卡的选项卡布局。在每个选项卡中,我都有一个包含新闻项的列表视图。当我单击新闻项时,我希望listview布局与我现在用于弹出窗口的xml布局切换(这有点作弊,但我不知道如何正确操作)。因此,如果有人有办法做到这一点,而不是使用弹出窗口,这将是最好的答案为我 充气布局的方法:打开视图时,ClassNotFoundException android.view.scrollview,android,xml,listview,popup,scrollview,Android,Xml,Listview,Popup,Scrollview,我试图膨胀一个包含scrollview的视图,在以下行膨胀视图时,我得到一个ClassNotFoundException android.view.scrollview: 视图布局=充气机。充气(R.layout.news\u article,null,true) 我自己找不到任何错误,谷歌搜索这个问题也帮不了我(不幸的是) 另一方面,这实际上也是我不知道怎么做的一个变通方法 情况: 我有一个包含3个选项卡的选项卡布局。在每个选项卡中,我都有一个包含新闻项的列表视图。当我单击新闻项时,我希望li
@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 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>
布局的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 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>
*********编辑*********
好的,弹出窗口现在显示,但我没有从中接收到任何事件当您膨胀布局时,您没有设置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);
我在我的代码中尝试了它,当我在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块并检查异常时,您可以很容易地看到这一点,因为它在那里显示异常。应该是ScrollView,而不是ScrollView。大写的vI完全错过了打字错误,谢谢!弹出窗口仍然没有显示,但我现在可能能够取得进展。不,他没有!news\u article是布局文件的名称,news\u article\u scroll是HorizontalScrollView的id!尝试此操作时,会出现以下错误:java.lang.UnsupportedOperationException:AdapterView中不支持addView(视图)。似乎无法向ListView添加内容?