[英]ClassNotFoundException re android.support.v4.view.ViewPager when inflating
[英]ClassNotFoundException android.view.scrollview when Inflating view
我正在嘗試給包含滾動視圖的視圖充氣,並在以下行的Inflating視圖中獲得一個ClassNotFoundException:android.view.scrollview:
View layout = inflater.inflate(R.layout.news_article,null,true);
我自己找不到任何錯誤,谷歌搜索這個問題對我沒有幫助(不幸)。
另一方面,這實際上也是我不知道該怎么做的解決方法。
情況:我有一個帶有3個標簽的標簽布局。 在每個標簽中,我都有一個包含新聞項目的列表視圖。 當我點擊新聞項目時,我希望使用xml布局切換listview布局我現在用於彈出窗口(它有點作弊,但我不知道如何正確地做到這一點)。 所以如果有人有辦法這樣做而不是使用彈出窗口,那對我來說將是最好的答案。
我誇大布局的方法:
@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>
** * **** 編輯 * ** * ****好的,彈出窗口現在顯示,但我沒有收到任何事件
我在我的代碼中嘗試了它,當我在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是正確的,但是inflater不能識別它並需要一個大寫'V'。
當你在它周圍放置一個try catch塊並檢查異常時,你可以很容易地看到它,因為它在那里說。
當您為布局充氣時,不設置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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.