屏幕空的空间底部

时间:2017-10-10 13:41:29

标签: android xml android-framelayout

我正在为我的应用设计一个布局,我使用的是FrameLayout,这很简单,

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/menu_slide"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#000000">

</FrameLayout>

这是我的活动代码

import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;

import java.util.ArrayList;
import java.util.Arrays;

import codopoliz.com.hscomply.Fragments.SlidingMenuFragment;
import codopoliz.com.hscomply.Models.MenuModel;
import codopoliz.com.hscomply.R;

public class MainActivity extends SlidingActivity {

    private ArrayList<String> menuList;
    private MenuModel[] menuItems;
    private View mCustomView;
    private TextView title;
    private SlidingMenu sm;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sliding);

        setStatusBarColorInMain();
        setBehindView();
        setupDrawer();

        final ActionBar actionBar = getSupportActionBar();
        LayoutInflater mInflater = LayoutInflater.from(this);
        mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setElevation(0);
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        actionBar.setCustomView(mCustomView, layoutParams);
        actionBar.setDisplayShowCustomEnabled(true);
        Toolbar parent = (Toolbar) mCustomView.getParent();
        parent.setContentInsetsAbsolute(0, 0);

        title = (TextView) mCustomView.findViewById(R.id.header_title);
        ImageView menubtn = (ImageView) mCustomView.findViewById(R.id.menu_Button);

        menubtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sm.toggle();
            }
        });

        menuList = getIntent().getStringArrayListExtra("menu");
        Object[] arrayObject = (Object[]) getIntent().getSerializableExtra("menuItems");
        menuItems = Arrays.copyOf(arrayObject , arrayObject.length, MenuModel[].class);
        Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
    }

    private void setBehindView() {
        setBehindContentView(R.layout.menu_slide);
        transactionFragments(SlidingMenuFragment.newInstance(), false, R.id.menu_slide, false, "MainFragment");
    }

    public void setActionBarTitle(String actionBarTitle) {
        title.setText(actionBarTitle);
    }

    public void transactionFragments(Fragment fragment, boolean backStackTag, int viewResource, boolean toogleOff, String fragmentTag) {
        final Fragment selectedFrag = getSupportFragmentManager().findFragmentByTag(fragmentTag);

        SlidingMenuFragment fragmentMenu = (SlidingMenuFragment) getSupportFragmentManager().findFragmentByTag("MainFragment");
        if (selectedFrag != null && selectedFrag.isVisible()) {
            toggle();
            return;
        }
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(viewResource, fragment, fragmentTag);
        if (backStackTag)
            ft.addToBackStack(null);
        ft.commit();
        if (!toogleOff) {
            toggle();
        }
    }

    private void setupDrawer() {
        sm = getSlidingMenu();
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    }

//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        switch (item.getItemId()) {
//            case android.R.id.home:
//                mSlidingMenu.toggle();
//                return true;
//            default:
//                return super.onOptionsItemSelected(item);
//        }
//    }
//
//    @Override
//    public void onBackPressed() {
//        if (mSlidingMenu.isMenuShowing()) {
//            mSlidingMenu.toggle();
//        } else {
//            super.onBackPressed();
//        }
//    }

    public ArrayList<String> getMenuListData() {
        return menuList;
    }

    public MenuModel[] getMenuItemsData() {
        return menuItems;
    }

    public void setStatusBarColorInMain(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = this.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(ContextCompat.getColor(this, R.color.color_status_in_main));
        }
    }
}

这是我的风格,

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <!--<item name="colorPrimary">@color/colorPrimary</item>-->
        <!--<item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
        <!--<item name="colorAccent">@color/colorAccent</item>-->
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppThemeSuper" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowContentOverlay">@null</item>

    </style>

    <!--For progress dialog-->
    <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">@color/colorPrimaryDark</item>
        <item name="android:textColorPrimary">@color/menu_white</item>
        <item name="android:background">@color/menu_white</item>
    </style>

</resources>

现在我在多个设备中进行了测试,其中大多数设计都运行良好。就像这样,

enter image description here

但在某些设备中,屏幕底部会出现一个白色的空白区域。像这样,

enter image description here

我还通过旋转设备进行检查,屏幕右侧出现白色区域。

如何从屏幕上删除此空白区域。请任何帮助将不胜感激..

0 个答案:

没有答案