2011-05-27 81 views
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> 

回答

0

为什么不直接使用其他LinearLayout中,如果你要堆叠起来像..?

相对并不意味着通过设计将元素叠加在一起。