如何解决适用于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?
相对并不意味着通过设计将元素彼此堆叠在一起。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。