【问题标题】:don't fill parent custom layout for action bar不要填充操作栏的父自定义布局
【发布时间】:2014-11-20 19:22:21
【问题描述】:

我有三个布局:1.calculate_actionbar_layout.xml 2.purchasemanager_actionbar_layout.xml 3.usermanagement_layout.xml

当我从操作栏中选择一个选项卡时,此选项卡的相关布局与操作栏中的项目显示。但不填充操作栏中的自定义布局。

Image of my app

主要活动代码:

ActionBar actionbar = getActionBar();
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
actionbar.setDisplayShowCustomEnabled(true);
View cView = getLayoutInflater().inflate(R.layout.usermanagement_layout, null);
actionbar.setCustomView(cView);
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

ImageView i=(ImageView) cView.findViewById(R.id.imageviewadduser);
i.setOnClickListener(this);

在选定的选项卡上更改操作栏:

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
final ActionBar actionbar = getActionBar();
View cView=null;
switch (tab.getPosition()) {
case 0:
cView = getLayoutInflater().inflate(R.layout.calculate_actionbar_layout, null);
 actionbar.setCustomView(cView);

//actionbar.setCustomView(R.layout.calculate_actionbar_layout);

break;
case 1:
cView = getLayoutInflater().inflate(R.layout.purchasingmanager_actionbar_layout, null);
actionbar.setCustomView(cView);

//actionbar.setCustomView(R.layout.purchasingmanager_actionbar_layout);
break;
case 2:
cView = getLayoutInflater().inflate(R.layout.usermanagement_layout, null);

actionbar.setCustomView(cView);

//actionbar.setCustomView(R.layout.usermanagement_layout);
break;
default:
break;
}
viewpager.setCurrentItem(tab.getPosition());
}

自定义布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#0d93d2"
android:weightSum="4"
android:gravity="center"
android:layout_gravity="center"
 >
<ImageView
android:id="@+id/imageviewusermanagment"
android:layout_width="0sp"
android:layout_weight="2.5"
android:layout_height="wrap_content"
android:src="@drawable/usermanagment"
android:scaleType="fitStart"
android:paddingLeft="20sp"

 />
 <ImageView
android:id="@+id/imageviewdeleteuser"
android:layout_width="0sp"
android:layout_weight=".5"
android:layout_height="wrap_content"
android:src="@drawable/deleteuser"

 />



<ImageView
android:id="@+id/imageviewedituser"
android:layout_width="0sp"
android:layout_weight=".5"
android:layout_height="wrap_content"
android:src="@drawable/edituser"/>

<ImageView
    android:id="@+id/imageviewadduser"
android:layout_width="0sp"
android:layout_weight=".5"
android:layout_height="wrap_content"
android:src="@drawable/adduser"
android:onClick="onClick"
     />

</LinearLayout>

【问题讨论】:

    标签: android-actionbar android-custom-view fill-parent


    【解决方案1】:

    将 onTabSelected 更改为:您应该将 LinearLayout.LayoutParams 定义为自定义布局操作栏

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        final ActionBar actionbar = getActionBar();
        View cView=null;
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT);
        switch (tab.getPosition()) {
        case 0:
    
             cView = getLayoutInflater().inflate(R.layout.calculate_actionbar_layout, null);
             cView.setLayoutParams(param);
             actionbar.setCustomView(cView);
    
            //actionbar.setCustomView(R.layout.calculate_actionbar_layout);
    
            break;
        case 1:
    
            cView = getLayoutInflater().inflate(R.layout.purchasingmanager_actionbar_layout, null);
            cView.setLayoutParams(param);
            actionbar.setCustomView(cView);
    
            //actionbar.setCustomView(R.layout.purchasingmanager_actionbar_layout);
            break;
        case 2:
             cView = getLayoutInflater().inflate(R.layout.usermanagement_layout, null);
             cView.setLayoutParams(param);
            actionbar.setCustomView(cView);
    
            //actionbar.setCustomView(R.layout.usermanagement_layout);
            break;
        default:
            break;
        }
        viewpager.setCurrentItem(tab.getPosition());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多