android - ActionBarSherlock with custom titlebar - weight distribution no working -
i'm trying implement custom title bar actionbarsherlock. title bar should have 2 buttons in left , right edges, , textview in center. textview should occupy space between 2 buttons.
i've tried setting layout_weight, reason had no effect @ all.
this custom layout have in res/layout
<linearlayout 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:orientation="horizontal" > <button android:id="@+id/btn_left" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="1" android:text="left" /> <textview android:id="@+id/header" android:layout_width="0dip" android:layout_height="match_parent" android:gravity="center_horizontal" android:layout_weight="4" android:text="header text" /> <button android:id="@+id/btn_right" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="1" android:text="right" /> </linearlayout>
right elements float left , have no idea why, doing wrong?
instead of using linerlayout try using relativelayout.
edit: made center text view strech buttons (make sure leave textview match_parent..
<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"> <button android:id="@+id/leftbutton" android:layout_alignparentleft="true".... <textview android:layout_centerhorizontal="true" android:layout_toleftof="@id/rightbutton" android:layout_torightof="@id/leftbutton" .... <button android:id="@+id/rightbutton" android:layout_alignparentright="true".... </relativelayout>
Comments
Post a Comment