頂部我有這樣的佈局:頂部關閉該LinearLayout
動態添加的TextView上的LinearLayout動態
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/rect"
android:id="@+id/searchRelativeLayout">
<LinearLayout
android:id="@+id/linearLayoutProc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:layout_alignParentRight="false"
android:gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="2dp">
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/inputQuery"
android:inputType="text"
android:ellipsize="middle"
android:hint="@string/search_hint"
style="@style/AutoCompleteTextViewOrangeAutoComplete"/>
</LinearLayout>
</RelativeLayout>
我想補充,沒有成功,一個TextView
,這是在年底, LinearLayout
應低於添加TextView
這是我的代碼:
RelativeLayout compareLayout = (RelativeLayout) layoutToShow.findViewById(R.id.searchRelativeLayout);
TextView compareItemOneMessage = new TextView(mContext);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
compareItemOneMessage.setLayoutParams(lp);
compareItemOneMessage.setTextAppearance(mContext, android.R.style.TextAppearance_Large);
compareItemOneMessage.setGravity(Gravity.CENTER);
compareItemOneMessage.setTypeface(fontBold);
compareItemOneMessage.setTextColor(mContext.getResources().getColor(R.color.orange));
compareItemOneMessage.setText("test");
compareLayout.addView(compareItemOneMessage);
新TextView
被添加,但它與EditText
的內容重疊
任何想法?
你好。謝謝,但它不起作用 – Favolas
因爲LinearLayout應該標記爲RelativeLayout。你也需要layout.addView(view,params); – easycheese
@easycheese不,如果你的意思是以上的解決方案,它不應該是RelativeLayout。我們將一個規則添加到relativelayout中的linearlayout,並且不必再次添加linearlayout視圖,因爲它已經添加了。這就是爲什麼我在那裏使用「getLayoutParams()」的原因。 –