I have problem with custom action bar, layout goes outside of the window or half appear , I have used four Relativelayout
inside Linearlayout
, just i want to make it something like tabbar. but the problem is that when i am using this layout, actionbar not fully appeared, i have posted xml and code below, i have also tried to show it in picture
actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/themecolor"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.30"
android:orientation="vertical" >
<TextView
android:id="@+id/papertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:text="Paper"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
<View
android:id="@+id/papertab"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@+id/paperv"
android:background="@android:color/white"
android:visibility="invisible" />
<View
android:id="@+id/paperv"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="vertical" >
<TextView
android:id="@+id/papertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:text="Explorer"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
<View
android:id="@+id/newstracktab"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@+id/newstrackv"
android:background="@android:color/white" />
<View
android:id="@+id/newstrackv"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:orientation="vertical" >
<TextView
android:id="@+id/papertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:text="Explorer"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
<View
android:id="@+id/Explorertab"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@+id/Explorerv"
android:background="@android:color/white"
android:visibility="invisible" />
<View
android:id="@+id/Explorerv"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:orientation="vertical" >
<ImageView
android:id="@+id/section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>
Mainactivity.java
public class MainActivity extends Activity {
public ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupActionBar();
}
public void setupActionBar() {
actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
View cView = getLayoutInflater().inflate(R.layout.actionbar, null);
actionBar.setCustomView(cView);
}
}
I got Something like this
I want something like this
Try this layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="@android:color/darker_gray"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.30"
android:orientation="vertical" >
<TextView
android:id="@+id/papertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:text="Paper"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
<View
android:id="@+id/papertab"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@+id/paperv"
android:background="@android:color/white"
android:visibility="invisible" />
<View
android:id="@+id/paperv"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="vertical" >
<TextView
android:id="@+id/papertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:text="Explorer"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
<View
android:id="@+id/newstracktab"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@+id/newstrackv"
android:background="@android:color/white" />
<View
android:id="@+id/newstrackv"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:orientation="vertical" >
<TextView
android:id="@+id/papertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:text="Explorer"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
<View
android:id="@+id/Explorertab"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@+id/Explorerv"
android:background="@android:color/white"
android:visibility="invisible" />
<View
android:id="@+id/Explorerv"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:orientation="vertical" >
<ImageView
android:id="@+id/section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.