我有custom_layout.xml:獲取計算器的錯誤,而試圖誇大自定義視圖
<?xml version="1.0" encoding="utf-8"?>
<com.example.MyCustomLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- different views -->
</com.example.MyCustomLayout>
而其類:
public class MyCustomLayout extends LinearLayout {
public MyCustomLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.custom_layout, this, true);
setUpViews();
}
//different methods
}
和活動,其中包括這樣的佈局:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
setUpViews();
}
和my_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.example.MyCustomLayout
android:id="@+id/section1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<com.example.MyCustomLayout
android:id="@+id/section2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
所以,我當我從刪除註釋塊一個問題:LayoutInflater.from(context).inflate(R.layout.custom_layout, this, true);
走在圖形模式my_activity.xml。 Eclipse認爲然後崩潰。它看起來像試圖多次膨脹我的自定義視圖,但我不明白爲什麼。我'在錯誤日誌中收到此錯誤,當我重新啓動日食:java.lang.StackOverflowError
它在電話中工作嗎? – dmon
noooooooooooooo – bluebyte