Issue
I have developed an app and it is currently in the BETA testing stage and I am working through bug fixes. This one particular issue has been driving me nuts; the issue I have is that certain android devices have bottom navigation bars, (the particular phone i am having this issue with this the HTC One M9) and this bottom navigation bar is causing the image I have on the view to cover up my Recycler View option.
I have tried all solutions to try and programmatically hide the bottom tool bar but nothing has worked. When I go into settings and hide the bottom navigation bar the display is correct again however I not everyone may be aware/have the 'hide bottom navigation bar' feature and so I wanted to overcome this alignment issue without the user having to make any further customisation.
This is my xml file: 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>
Here is the .java file corresponding to the above .xml file: 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) {
}
}
Please find the screenshots below (first with, second one without navigation bar)
As you can see, the bottom bar is pushing the ImageView up causing it to cover the second option in the recylerview, I don't want this to happen. I would like the view to display how it does without the bottom Navigation bar even with the bottom bar active. Hope this makes sense. Is this possible?
I think it is something real small i am failing to see.
Any help would be highly appreciated.
Solution
Solution
(check comments for more information)
Change size of the RecyclerView
, I mean take smaller screen device. If you don't have it, please make a 4' screen emulator. Check how it looks on it.
If needed create custom thinner toolbar - i don't think you need as wide as standard for it.
You can also change height of RecyclerView
. Then if it looks good check on HTC One.
Keep in your mind that there are some screen devices and Android version. As I see your HTC has Lollipop (5.x) version. Check also how it looks on Kitkat and older by creating some more emulators or buying some cheap different screen-sized phones.
Hope it help
Answered By - piotrek1543
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.