0
所以這裏是我的交易。我有一個應用程序連接到一個獲取JSON數據並將其解析出來的PHP站點。 JSON解析完美無缺,因此無需深入研究。我需要允許來自PHP站點的無限量的項目,所以我創建了一個循環來爲每個項目膨脹一個XML文件。我的問題是,TextView項目lblShared和lblSaid重疊lblQuote。他們假設在lblQuote下面對齊。我會發布我的來源的基礎知識,請只需要更多,如果需要。適用於Android的Java:充氣XML佈局,TextView的重疊
LinearLayout l = (LinearLayout) findViewById(R.id.myMainLayout);
LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = linflater.inflate(R.layout.myviews, null);
TextView tvQuote = (TextView) myView.findViewById(R.id.lblQuote);
//Set an id to know which quote is in use
tvQuote.setId(i);
TextView tvShared = (TextView) myView.findViewById(R.id.lblShared);
TextView tvSaid = (TextView) myView.findViewById(R.id.lblSaid);
//Change name dynamically
tvQuote.setText((strQuote).toString());
tvShared.setText(("Shared by: " + strShared).toString());
tvSaid.setText(("Said by: " + strSaid).toString());
l.addView(myView);
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:id="@+id/myMainLayout"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content">
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Title"
android:id="@+id/lblTitle"
android:textSize="16px"
android:padding="5px"
android:textStyle="bold"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>
myviews.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip">
<TextView
android:id="@+id/lblQuote"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/lblShared"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblQuote"
android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/lblSaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblQuote"
android:layout_alignParentLeft="true"/>
</RelativeLayout>