我想要一個的LinearLayout添加到scrolview 這是我的代碼 代碼編譯,但它並沒有告訴我新的佈局添加的LinearLayout當前視圖不工作
這是原始佈局(即我想補充的話)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_margin="15dp"
android:layout_marginTop="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="@+id/ViewHistoryImageLayout">
<ImageView
android:id="@+id/HistoryImage"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.76"
android:gravity="center"
android:padding="10dp"
android:src="@drawable/upload"
android:contentDescription="@string/HistoryImage"/>
<TextView
android:id="@+id/TranslatedText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.12"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/translateImageButton" />
</LinearLayout>
,這是我想補充幾次佈局:
<LinearLayout 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/TranslationMenuLayout" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="5" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
,並添加新的佈局的Java代碼:
setContentView(R.layout.activity_view_history_image);
ScrollView sv = new ScrollView(this);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View ll = inflater.inflate(R.layout.translation_menu, null);
sv.addView(ll);
代碼編譯的罰款,並在應用程序正在運行,但沒有任何反應 有與.xml文件的一個問題?
TNX
現在您將scrollview佈局添加到動態創建的滾動視圖。這肯定會失敗。 – ePeace