【问题】
Android中一个xml布局文件中,尝试给TextView中加入:
android:layout_weight="2"
结果出错:
Invalid layout param in a RelativeLayout: layout_weight |
如图:
【解决过程】
1.然后此时,自己才注意到,原来此处是:
RelativeLayout
而不是
LinearLayout
2.所以去改为:
Linear Layout | Android Developers
中的:LinearLayout
3.虽然错误很明显,但是:
很多时候,在不同的时候,需要使用LinearLayout或者RelativeLayout,才能达到对应的目的。
而此时,往往需要多次尝试,才能达到所需的效果。。。
所以,此处,虽然改回LinearLayout
但是有些效果,是RelativeLayout才能实现的。。。
所以也是不得已为之。。。。
【总结】
还是需要对于LinearLayout和RelativeLayout,更加透彻的了解,才能更好的控制Android中的UI显示效果。
【后记】
1.后来改了多次,最后改为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | android:layout_width = "match_parent" android:layout_height = "match_parent" android:paddingLeft = "20sp" android:orientation = "horizontal" android:focusable = "true" android:focusableInTouchMode = "true" > ...... < TextView android:id = "@+id/variableLabel" android:layout_centerVertical = "true" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:gravity = "center" android:layout_toRightOf = "@id/variableStatus" android:paddingLeft = "5sp" /> </ RelativeLayout > |
才基本达到所需效果。
转载请注明:在路上 » 【已解决】Android中xml布局文件出现提示:Invalid layout param in a RelativeLayout: layout_weight