0

我需要建议来在我现有的项目中实施 Facebook 导航。

主布局.xml

<?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="vertical" >

<fragment
    android:id="@+id/fragment_actionbar"
    android:name="com.newvisioninteractive.android.mystyle.fragment.ActionbarFragment"
    android:layout_width="fill_parent"
    android:layout_height="44dp"
    android:layout_gravity="fill_horizontal" >

    <!-- Preview: layout=@layout/fragment_actionbar -->
</fragment>

<FrameLayout
    android:id="@+id/fragment_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

ActionbarFragment.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/actionbar_root"
    android:layout_width="fill_parent"
    android:layout_height="44dp"
    android:background="@color/accent" >  

    <ImageView
    android:id="@+id/actionbar_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:paddingLeft="7dp"
    android:paddingRight="7dp"
    android:src="@drawable/ic_text_header"
    android:clickable="true"
    android:background="@drawable/bg_actionbar_highlight" />

    <LinearLayout 
    android:id="@+id/button_container" 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/actionbar_title"
    android:orientation="horizontal"
    android:gravity="right" />

这是我对应的片段活动类。

public class ActionbarFragment extends Fragment {

private View         mRoot;   
private ImageView    mHomeButton;
private LinearLayout mButtonContainer;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Activity activity = getActivity();
    //if (activity)
    mRoot = inflater.inflate(R.layout.fragment_actionbar, container, false);
    /*} else {
        mRoot = inflater.inflate(R.layout.fragment_actionbar_no_button, container, false);
    }*/


    mHomeButton      = (ImageView) mRoot.findViewById(R.id.actionbar_title);
    mButtonContainer = (LinearLayout) mRoot.findViewById(R.id.button_container);

    mHomeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Activity activity = getActivity();

            if (activity != null) {
                // Launch MyStyleActivity and clear all other Activities from the stack.
                Intent intent = new Intent(activity, MyStyleActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        }

    });

    return mRoot;
}

/**
 * Remove all buttons from the actionbar. 
 */
public void resetButtons() {
    if (mButtonContainer != null) {
        mButtonContainer.removeAllViews();
    }
}

/**
 * Add any view as a button to the actionbar.
 * 
 * @param view The view that will act as a button.
 */
public void addButton(View view) {
    if (mButtonContainer != null && view != null) {

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);

        View seperator = makeButtonSeperator();

        mButtonContainer.addView(seperator, seperator.getLayoutParams());
        mButtonContainer.addView(view, params);
    }
}

/**
 * Utility method for adding the vertical separator for actionbar buttons.
 * 
 * @return The separator.
 */
private FrameLayout makeButtonSeperator() {
    FrameLayout seperator = new FrameLayout(getActivity());

    final float scale = getResources().getDisplayMetrics().density;

    seperator.setLayoutParams(new LinearLayout.LayoutParams((int) (scale * 2), LinearLayout.LayoutParams.FILL_PARENT));
    seperator.setBackgroundColor(getResources().getColor(R.color.selector_highlight));

    return seperator;
}

}

我的问题是,在课堂上,当我单击 mHomeButton 时,当前布局应该像 facebook 一样移动或滑出到右侧。

我真的用主布局中使用的这个片段来构建。当我为片段设置动画时,只需要移动而不是整个布局。

提前致谢。

4

0 回答 0