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

时间:2016-01-01 15:44:34

标签: android android-layout android-imageview android-recyclerview android-navigation

我开发了一个应用程序,它目前处于BETA测试阶段,我正在修复错误。这一个特殊问题让我疯狂;我的问题是,某些Android设备有底部导航栏,(特定的手机我有这个HTC One M9的问题)和这个底部导航栏导致我在视图上的图像掩盖我的Recycler视图选项。

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

这是我的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中的第二个选项,我不希望这种情况发生。我希望视图显示它的工作方式,如果没有底部导航栏,即使底部栏处于活动状态。希望这是有道理的。这可能吗?

我认为这是一个非常小的东西,我没有看到。

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

解决方案

(查看评论以获取更多信息)

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

如果需要创建自定义精简工具栏 - 我认为您不需要它的标准范围。

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

请记住,有一些屏幕设备和Android版本。我看到你的HTC有Lollipop(5.x)版本。通过创建更多模拟器或购买一些便宜的不同屏幕大小的手机,检查它在Kitkat和更老的外观。

希望有所帮助