我有自定义操作栏的问题,布局在窗口外面或者一半出现,我在Relativelayout
内使用了四个Linearlayout
,我想让它像tabbar一样。但问题是,当我使用这个布局时,动作栏没有完全出现,我已经在下面发布了xml和代码,我也尝试在图片中显示它
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);
}
}
我得到了类似的东西
我想要这样的东西
答案 0 :(得分:0)
尝试此布局
<?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>