Xml code is as follows
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.testforlayout.MainActivity" > <RelativeLayout Android:id="@ plus id/setTime1 " android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginLeft="50dp" android:layout_marginTop="250dp" android:orientation="vertical" android:background="#00FF00" > <TimePicker Android:id="@ plus id/timePicker1 " android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginLeft="50dp" /> <TextView Android:id="@ plus id/text11 " android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/timePicker1" Android:text= "test" android:textSize="30sp" /> </RelativeLayout> </RelativeLayout>
However, the contents of TextView will not be displayed. I want to know about Why is this? (Under what circumstances can you not see the controls you have set up)
And sometimes the control declared later is set to toLeftOf, and the previous control cannot see the control.
(I personally do not want to set too many accurate DP values)
In addition, I also want to know the details of each attribute in Android’s relative layout. In the end, setting several necessary attributes to a control in the relative layout will enable it to be placed in a proper and accurate position (for example, I declared a control first, and I want the vertical midpoint of the control declared later to be aligned with the vertical midpoint of the control declared earlier), and how can it be effective at present
To organize the placement of Android controls, I also hope to recommend a good article to guide me
I hope The Con Artists can answer my questions one by one, and I am very grateful!
My answers are all more popular explanations, because I am not very clear about the real principle. Based on experience:
The first problem is that the analysis of ViewGroups including RelativeLayout is child-by-child, that is, each View in ViewGroup is limited to viewgroup and views that have already been laid out. If you add an Android: layout _ alignparentbottom = “true” to your TimePicker, you will find TextView is out, which means TextView is laid out, and only depends on TimePicker to be laid out on the screen. Therefore, the layout should generally be from top to bottom and from left to right.
Second question:http://blog.csdn.net/jiangxinyu/article/details/8611228A casual search of a blog is enough to solve your second problem.
The third question: This comes from experience and study. Look at other people’s excellent source code and Baidu Google.
My experience is that simple layout is RelativeLayout and LinearLayout, complex need a lot of nesting is to use RelativeLayout nested LinearLayout, more use layout_weight. There is more than one kind of excellence, depending on one’s own habits.