Today when doing an android application, use a layout to achieve the results shown below:
When two buttons on both sides, but when was the middle of the layout match_parent between left and right, that is between the full layout around, here is the layout file: main.xml
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical">layout = "@ layout / top_bar" /> android: id = "@ + id / realtabcontent"
android: layout_width = "match_parent"
android: layout_height = "0dip"
android: layout_weight = "1" />android: id = "@ + id / tabhost"
android: layout_width = "match_parent"
android: layout_height = "wrap_content">
top_bar.xml:
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: background = "@ drawable / topbar_bg">android: id = "@ + id / topbar_left_btn"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_alignParentLeft = "true"
android: layout_centerVertical = "true"
android: layout_marginLeft = "10dip"
android: background = "@ color / transparent"
android: onClick = "leftBtnClick"
android: src = "@ drawable / add_friend" />android: id = "@ + id / top_bar_title"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_centerInParent = "true"
android: gravity = "center"
android: textColor = "@ color / white"
android: textSize = "20sp" />android: id = "@ + id / topbar_right_btn"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_alignParentRight = "true"
android: layout_centerVertical = "true"
android: layout_marginRight = "10dip"
android: background = "@ color / transparent"
android: onClick = "rightBtnClick"
android: src = "@ drawable / add_friend" />android: id = "@ + id / radio_group"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: layout_centerVertical = "true"
android: layout_toLeftOf = "@ id / topbar_right_btn"
android: layout_toRightOf = "@ id / topbar_left_btn"
android: orientation = "horizontal"
android: visibility = "visible">android: id = "@ + id / auth_tab"
android: layout_width = "wrap_content"
android: layout_weight = "1"
android: background = "@ drawable / add_btn_focus"
android: button = "@ null"
android: checked = "true"
android: gravity = "center" />android: id = "@ + id / original_tab"
android: layout_width = "wrap_content"
android: layout_weight = "1"
android: background = "@ drawable / add_btn_focus"
android: button = "@ null"
android: gravity = "center" />
Set up between the two button:
android: layout_toLeftOf = "@ id / topbar_right_btn"
android: layout_toRightOf = "@ id / topbar_left_btn"
Meanwhile match_parent
This time I just do not call in the Activity:
mAddFriendBtn = (ImageButton) findViewById (R.id.topbar_right_btn);
Displayed correctly:
; If once the call:
mAddFriendBtn = (ImageButton) findViewById (R.id.topbar_right_btn);
On display:
I do not know in the end what is the reason when (models is os2.3.5, when the code sdk 4.0)
Finally, only through
android: onClick event to listen for the
Reply:
Did not see it, Bangding.
RelativeLayout replaced with LinearLayout you?
Reply:
android: id = "@ + id / radio_group"
android: layout_width = "match_parent"
Changed
android: id = "@ + id / radio_group"
android: layout_width = "0dip"
android: layout_weight = "1"
Try
Reply:
According to the first floor and second floor of the answers, you can now achieve that kind of effect, while:
mAddFriendBtn = (ImageButton) findViewById (R.id.topbar_right_btn);
Also not affect the layout.
Topbar.xml changed:
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: background = "@ drawable / topbar_bg"
android: orientation = "horizontal">android: id = "@ + id / topbar_left_btn"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center_vertical"
android: layout_marginLeft = "10dip"
android: background = "@ color / transparent" />android: id = "@ + id / top_bar_title"
android: layout_width = "0dip"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: layout_weight = "1"
android: gravity = "center"
android: textColor = "@ color / white"
android: textSize = "20sp" />android: id = "@ + id / radio_group"
android: layout_width = "0dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: orientation = "horizontal"
android: visibility = "gone">android: id = "@ + id / auth_tab"
android: layout_width = "wrap_content"
android: layout_weight = "1"
android: button = "@ null"
android: checked = "true"
android: gravity = "center" />android: id = "@ + id / original_tab"
android: layout_width = "wrap_content"
android: layout_weight = "1"
android: button = "@ null"
android: gravity = "center" />
android: id = "@ + id / topbar_right_btn"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center_vertical"
android: layout_marginRight = "10dip"
android: background = "@ color / transparent" />
But why is there such a problem, or did not get to know the reason
Reply:
RadioGroup above attributes
android: visibility = "gone"TextView should be placed where a misplaced
Reply:
If there is a android: visibility = "gone" certainly changes the layout of your location, the best android: visibility = "invisible"
Reply:
Ah, I just let textview or below RadioGroup centered
As with the first method, why cause strange to change the layout of this are not clear what is the reason
Reply:
Layout of such a rule, you should use LinearLayout
Reply:
Your original radio_group of android_width = "match_parent", is it the right to occupy all the space, so invisible to the right of the Add button.
Reply:
But I set
android: layout_toLeftOf = "@ id / topbar_right_btn"
Also, if there is no call
mAddFriendBtn = (ImageButton) findViewById (R.id.topbar_right_btn);
Displayed normal, if it gets through this button once instance, will occupy space on the right
Reply:
This strange performance is concerned with match_parent and RelativeLayout.
No comments:
Post a Comment