当底部导航栏处于活动状态时,ImageView 覆盖 Recyclerview 选项

ImageView is covering Recyclerview Options when bottom Navigation Bar is Active

我开发了一个应用程序,目前处于 BETA 测试阶段,我正在修复错误。这个问题一直让我抓狂;我遇到的问题是某些 android 设备有底部导航栏,(特别是 phone 我在使用 HTC One M9 时遇到了这个问题)并且这个底部导航栏导致了我的图像掩盖我的 Recycler View 选项的视图。

我已经尝试了所有解决方案来尝试以编程方式隐藏底部工具栏,但没有任何效果。当我进入设置并隐藏底部导航栏时,显示再次正确,但我不是每个人都可能 aware/have 'hide bottom navigation bar' 功能,所以我想克服这个对齐问题,而无需用户进行任何操作进一步定制。

这是我的 xml 文件:festivals.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:fitsSystemWindows="true"
              android:clipToPadding="false"
                android:windowTranslucentStatus="false"
                android:statusBarColor="@android:color/transparent"
                android:navigationBarColor="@android:color/transparent">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"/>

    <!-- A RecyclerView with some commonly used attributes -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/festivals_recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:fitsSystemWindows="true"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="470dp"
        android:id="@+id/imageView"
        android:src="@drawable/ganesh_red"
        android:layout_alignParentBottom="true  android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" android:scaleType="centerCrop"
        />

</RelativeLayout>

这里是上面.xml文件对应的.java文件:FestivalsActivity.java

public class FestivalsActivity extends BaseActivity implements RecyclerViewAdapterFestivals.ClickListener {

    private RecyclerView mRecyclerView;

    //Creating an instance of the adapter object
    private RecyclerViewAdapterFestivals adapter;

    private static final int ITEM_COUNT = 2;

    @Override
    //public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    protected void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        setContentView(R.layout.festivals);

        //This line of code will set the View to full screen without any trimming
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        //This line will forcefully hide the bottom navigation bar on devices that have them
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

        //Setting the orientation to Portrait Only
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        //Calling Activate Toolbar method (with the Back button enabled)
        activateToolBar();

        //Instantiating the recycler view as defined in national_committee
        mRecyclerView=(RecyclerView) findViewById(R.id.festivals_recycler_view);

        //Adding item decoration. Recycler view divider
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST));

        //Initialising the adapter - Passing in the activity and the getData method
        adapter=new RecyclerViewAdapterFestivals(this, getData());

        //Here passing in the click listener into the Adapter. 'this' signifies that it is the fragment that handles the click listener.
        //This is possible as the on Click Listener interface is being implemented.
        adapter.setClickListener(this);

        //Setting the adapter
        mRecyclerView.setAdapter(adapter);

        //Setting the Layout
        //mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar enough_food it is present.
        //getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.

        //int id = item.getItemId();

        return super.onOptionsItemSelected(item);
    }

    //Creating an array list of information objects that can be passed into the recycler view
    public static List<SubInformation> getData() {

        List<SubInformation> data = new ArrayList<>();

        //String array of text for the recycler view
        String[] text = {"January - June", "July - December"};

        //For loop to go through entire length of the menu string
        for(int i=0; i<ITEM_COUNT; i++){

            data.add(new SubInformation(text[i]));
        }

        return data;
    }

    @Override
    public void itemClicked(View view, int position) {

    }
}

请找到下面的屏幕截图(第一个有导航栏,第二个没有导航栏)

如您所见,底部栏将 ImageView 向上推,导致它覆盖 recylerview 中的第二个选项,我不希望这种情况发生。我希望视图显示它在没有底部导航栏的情况下的表现,即使底部栏处于活动状态。希望这是有道理的。这可能吗?

我认为这是我没看到的非常小的东西。

非常感谢任何帮助。

解决方案

(查看评论了解更多信息)

更改 RecyclerView 的大小,我的意思是采用较小的屏幕设备。如果您没有,请制作一个 4' 屏幕模拟器。检查它的外观。

如果需要创建自定义更细的工具栏 - 我认为您不需要像标准一样宽。

您还可以更改 RecyclerView 的高度。然后,如果它看起来不错,请检查 HTC One。

请记住,有一些屏幕设备和 Android 版本。正如我所见,您的 HTC 有 Lollipop (5.x) 版本。通过创建更多模拟器或购买一些便宜的不同 screen-sized 手机,检查它在 Kitkat 和更早版本上的外观。

希望对您有所帮助