适用于Android的Java:膨胀XML布局,TextView重叠

问题描述

|| 所以这是我的交易。我有一个连接到PHP站点的应用程序,该站点获取JSON数据并将其解析出来。 JSON解析工作完美,因此无需深入了解。我需要允许来自PHP站点的无限数量的项目,所以我正在创建一个循环为每个项目添加XML文件。我的问题是TextView项目lblShared和lblSaid重叠了lblQuote。假设它们在lblQuote下面对齐。我将发布源代码的基础知识,如果需要的话,请提出更多要求。
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>
    

解决方法

        如果要像那样堆叠它们,为什么不使用另一个LinearLayout? 相对并不意味着通过设计将元素彼此堆叠在一起。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...