in navigation drawer, when i push a button or anything else, drawer gets closed. What is the problem?
I search on internet but I didn't find anything that is different than my codes. Maybe there are some mistakes but I have not found them.
codes:
index.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bbb9b9b9">
<ListView
android:id="#+id/listViewDrawer"
android:layout_width="240dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:background="#fff"
android:padding="3dp"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:divider="#android:color/transparent">
</ListView>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:weightSum="10">
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="#+id/btnMalt"
android:layout_weight="1.5"
android:src="#drawable/mal" />
<EditText
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="#+id/legerin_ett"
android:layout_weight="5.5"
android:hint="#string/legerin_text" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="#+id/btnLegerint"
android:layout_weight="1.5"
android:src="#drawable/legerin" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="#+id/btnDerkevet"
android:layout_weight="1.5"
android:src="#drawable/derkeve" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/sernavt"
android:gravity="center"
android:text="sepana tirşikê ji bo telefonên jîr"
android:textStyle="bold"
android:textColor="#ff000000"
android:textSize="20dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp" />
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/listViewt"
android:layout_gravity="center_horizontal"
android:layout_weight="9"
android:layout_marginBottom="5dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="#string/peyameke_binivise"
android:id="#+id/buttonPeyamBinivise"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout >
</android.support.v4.widget.DrawerLayout>
in main.java related codes:
NuceMijarAdapter adapter1 = new NuceMijarAdapter(Index.this,R.layout.list_mijar_layout,arr);
lvDrawer.setAdapter(adapter1);
private class NuceMijarAdapter extends ArrayAdapter<String> {
private ArrayList<String> items;
public NuceMijarAdapter(Context context, int textViewResourceId, ArrayList<String> items) {
super(context, textViewResourceId, items);
this.items = items;
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_mijar_layout, null);
}
final String o = items.get(position);
if (o != null) {
String htmlText = o.replace("<a href=\"index.php?","<a href=\"http://www.tirsik.net/index.php?")
.replace("padding-left:8px","padding-left:1px")
.replace(" » ","");
final NuceMijarIro nuce = mijarIroAction(htmlText);
Button tvMijar = (Button) v.findViewById(R.id.tvMijar);
Button tvHejmar = (Button) v.findViewById(R.id.tvHejmar);
tvMijar.setText(nuce.mijar);
tvHejmar.setText(nuce.hejmar);
tvMijar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("url: ", nuce.link);
if(nuce.link.contains("index.php?mijar")) {
urlIndex = nuce.link;
if(teketin) mijarRasthatiTeketi("bnr");
else mijarRasthati("bnr");
}
}
});
}
return v;
}
}
I had the same problem once.
I had a RecyclerView NavigationDrawer and by just moving the Navigation code to the bottom of the xml file my problem got solved.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//some code here for the body of your activity
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#ffffff"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
hope it works for you too...
For more explanation,
<ListView
android:id="#+id/listViewDrawer"
android:layout_width="240dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:background="#fff"
android:padding="3dp"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:divider="#android:color/transparent">
</ListView>
Is going to be your Content and other contents gonna be your NavigationDrawer actually.
Please see how it works:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
Which said:
the following layout uses a DrawerLayout with two child views: a
FrameLayout to contain the main content (populated by a Fragment at
runtime), and a ListView for the navigation drawer.
And use NavigationDrawer which that comes from with new SupportLibrary.
Related
<LinearLayout
android:id="#+id/layout_question_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp"
>
<Button
android:id="#+id/btn_question_backButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/backicon_round"/>
<TextView
android:id="#+id/text_question_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#color/color_green"
android:text="Error"
android:textSize="19dp"
/>
</RelativeLayout>
<ImageView
android:id="#+id/image_question_detail_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="2">
<TextView
android:id="#+id/text_question_detail_userComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:layout_marginBottom="25dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3">
<ListView
android:id="#+id/list_question_detail_expComments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"></ListView>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Now, I set layout for title on the top. Then, a Imageview, a textview and a listview follow below this layout, and only 1 textview is inside listview.
listview can vary in size.
The problem is, if the size of the listview is very big, I can only scroll the screen assigned to listview.
But, I want scroll the entire screen.
To solve this problem, I added scrollview outside of the first linearlayout.
However, It didn't work.(the imageview disappeared)
What can I do?
you can make your listview addheaderview,and put your imageview and textview into headerview
yourlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_question_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp">
<Button
android:id="#+id/btn_question_backButton"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="#+id/text_question_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Error"
android:textColor="#000000"
android:textSize="19dp"
/>
</RelativeLayout>
<ListView
android:id="#+id/list_question_detail_expComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"></ListView>
lv_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:id="#+id/image_question_detail_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/text_question_detail_userComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:textSize="20dp" />
Activity.class
public class MainActivity extends AppCompatActivity {
private ListView list_question_detail_expComments;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_question_detail_expComments = (ListView) findViewById(R.id.list_question_detail_expComments);
View lvHeaderView = View.inflate(this,R.layout.lv_header,null);
list_question_detail_expComments.addHeaderView(lvHeaderView);
list_question_detail_expComments.setAdapter(new LvAdapter());
}
private class LvAdapter extends BaseAdapter{
#Override
public int getCount() {
return 20;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
TextView tv = new TextView(MainActivity.this);
tv.setText("test"+i);
return tv;
}
}
}
I am trying to change programmatically the background color of ListView item when the user tap on it. I am trying to implement a solution using setOnItemClickListener, but I have trouble making the listener work. Here is my code:
ArrayList<Integer> menuIcons = app.Theme.Icons.getMenuPanelIconList();
ArrayList<String> menuText = app.Languages.Active.getMenuPanelItemNames();
listview_menu = (ListView) findViewById(R.id.listview_menu);
listview_menu.setBackgroundColor(Color.parseColor("#" + app.Theme.ThemeBackColor));
MenuPanelListViewAdapter menuPanelListViewAdapter = new MenuPanelListViewAdapter(ActivityMain.this, menuIcons, menuText);
listview_menu.setAdapter(menuPanelListViewAdapter);
listview_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adpterView, View view, int position,
long id) {
for (int i = 0; i < listview_menu.getChildCount(); i++) {
if(position == i ){
listview_menu.getChildAt(i).setBackgroundColor(Color.BLUE);
}else{
listview_menu.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
}
}
});
Here is my mainactivity.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:id="#+id/relativelayout_base"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/relativelayout_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize">
<LinearLayout
android:id="#+id/linearlayout_menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:clickable="true"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:id="#+id/imageview_menu"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/menushow_g" />
</LinearLayout>
<com.hotelstayapp.android.custom.CustomTextView
android:id="#+id/customtextview_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/linearlayout_menu"
android:textColor="#FFFFFF"
android:textSize="27sp"
android:ellipsize="end"
android:singleLine="true"
android:paddingBottom="1dp"/>
</RelativeLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.hotelstayapp.android.UI.ActivityMain"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relativelayout_toolbar">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout_menupanel"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left">
<RelativeLayout
android:id="#+id/relativelayout_menuheader"
android:layout_width="match_parent"
android:layout_height="130dp"
android:clickable="true">
<com.facebook.drawee.view.SimpleDraweeView
fresco:actualImageScaleType="centerCrop"
android:id="#+id/imageview_menubgimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="240dp"
android:layout_height="70dp"
fresco:actualImageScaleType="fitCenter"
android:id="#+id/imageview_menulogo"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<ListView
android:id="#+id/listview_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/relativelayout_menuheader"
android:layout_gravity="right"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:paddingTop="10dp"
android:smoothScrollbar="true"
android:focusable="false"
android:focusableInTouchMode="false">
</ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Here is my ListView items layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:paddingBottom="14dp"
android:paddingTop="14dp"
android:paddingLeft="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.8"
android:gravity="center">
<ImageView
android:layout_width="23dp"
android:layout_height="23dp"
android:id="#+id/imageViewIcon"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:src="#drawable/menuhome_g"
android:layout_centerHorizontal="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.2"
android:paddingLeft="15dp"
android:gravity="center_vertical">
<com.hotelstayapp.android.custom.CustomTextView
android:id="#+id/textViewMenuItemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|left"
android:text="Home"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/viewMenuDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#eeeeee"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"></View>
</LinearLayout>
First change background of all item to transperent then set clicked view's background to your desired color like below.
MenuPanelListViewAdapter menuPanelListViewAdapter = new MenuPanelListViewAdapter(ActivityMain.this, menuIcons, menuText);
listview_menu.setAdapter(menuPanelListViewAdapter);
listview_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adpterView, View view, int position,
long id) {
for (int i = 0; i < listview_menu.getChildCount(); i++) {
listview_menu.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
view.setBackgroundColor(Color.BLUE);
menuPanelListViewAdapter.notifyDataSetChanged(); // this is importent
}
});
I have used DevsmartLib-Android
to create HorizontalListView
Below is the layout for the HorizontalListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context="com.test.demo.HorizontalListViewActivity">
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd"
/>
</LinearLayout>
and this is the implementation in the adapter. I am unable to figure out how to inflate this HorizontalListView multiple times to get the desired result
private BaseAdapter mAdapter = new BaseAdapter() {
private View.OnClickListener mOnButtonClicked = new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(HorizontalListViewActivity.this, "Item Clicked"+v, Toast.LENGTH_SHORT).show();
}
};
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View vv = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem, null);
TextView title = (TextView) vv.findViewById(R.id.title);
Button button = (Button) vv.findViewById(R.id.clickbutton);
button.setOnClickListener(mOnButtonClicked);
title.setText(dataObjects[position]);
return vv;
}
This is how the app looks now. I am trying to inflate the HorizontalListView inside a listview. How do I take this further from here?
I don't understand 'how to inflate this HorizontalListView multiple times to get the desired result', but Maybe you want put many HorizontalListView in One Layout.
If my understanding is correct, here is your answer.
Using ScrollView to inflate layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/listview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd"
/>
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/listview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd"
/>
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/listview3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd"
/>
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/listview4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd"
/>
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/listview5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Hi I am using android NavigationView. I want to change the icons direction to RTL instead of LTR like this:
How can I do this?
you can use listview inside the navigationview like what i did. the benefit of this is that you can have better control on this:
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/header"
>
<ListView
android:id="#+id/navigationmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="192dp"
android:background="#android:color/white">
</ListView>
</android.support.design.widget.NavigationView>
and nav item should be like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cardview_dark_background"
>
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:src="#drawable/viewlist"
/>
<TextView
android:id="#+id/tvlstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_marginRight="30dp"
android:textColor="#color/colorPrimary"
/>
</RelativeLayout>
and navcustomadapter like this:
package com.example.android.dezcook;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
/**
* Created by Android on 6/4/2016.
*/
public class navCustomAdapter extends BaseAdapter {
String[] result;
Context context;
int[] imageId;
private static LayoutInflater inflater=null;
public navCustomAdapter(MainActivity mainActivity,String[] prgmNameList,int[] prgImages)
{
result=prgmNameList;
imageId=prgImages;
context =mainActivity;
inflater =(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount()
{
return result.length;
}
#Override
public Object getItem(int position)
{
return position;
}
#Override
public long getItemId(int position)
{
return position;
}
public class Holder
{
TextView tv;
ImageView img;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent)
{
Holder holder=new Holder();
View rowView;
rowView=inflater.inflate(R.layout.navitem,null);
holder.tv=(TextView)rowView.findViewById(R.id.tvlstName);
holder.img=(ImageView)rowView.findViewById(R.id.img);
holder.tv.setText(result[position]);
holder.img.setImageResource(imageId[position]);
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context,"you Clicked "+result[position],Toast.LENGTH_LONG).show();
}
}
);
return rowView;
}
}
finally call it in main activity like this:
ListView lv=(ListView)findViewById(R.id.navigationmenu);
lv.setAdapter(new navCustomAdapter(this,navItem,prgmImages)
Just figure it out!
Try adding these attributes to NavigationView in your layout file.
android:layoutDirection="rtl"
android:textDirection="rtl"
Screenshot
Note: It seems its working on API 17 and higher
I had this problem.My app was "ltr" and I wanted to view drawer in "rtf" mode.
My solution:
In Navigation view I cleared :
app:menu="#menu/drawer_menu"
app:headerLayout="#layout/drawer_nav_header"
and replaced:
include layout="#layout/drawer_nav_header"/>
include layout="#layout/ly_custom_menu_item"/>
<include layout="#layout/fragment_map" />
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#color/white"
android:fitsSystemWindows="true">
<!--app:menu="#menu/drawer_menu"
app:headerLayout="#layout/drawer_nav_header"-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/drawer_nav_header"/>
<include layout="#layout/ly_custom_menu_item"/>
</LinearLayout>
</android.support.design.widget.NavigationView>
ly_custom_menu_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearItemAnalysis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/picSize_50"
android:orientation="horizontal"
android:gravity="center_vertical|right"
android:paddingRight="#dimen/margin_dp_8"
android:foreground="?selectableItemBackgroundBorderless">
<TextView
android:text="navAnalysis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/margin_dp_16"/>
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_analysis_menu"
app:layout_constraintEnd_toEndOf="parent"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearItemRouting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/picSize_50"
android:orientation="horizontal"
android:gravity="center_vertical|right"
android:paddingRight="#dimen/margin_dp_8"
android:foreground="?selectableItemBackgroundBorderless">
<TextView
android:text="routing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/margin_dp_16"/>
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_routing"
app:layout_constraintEnd_toEndOf="parent"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearItemAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/picSize_50"
android:orientation="horizontal"
android:gravity="center_vertical|right"
android:paddingRight="#dimen/margin_dp_8"
android:foreground="?selectableItemBackgroundBorderless">
<TextView
android:text="navAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/margin_dp_16"/>
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_address"
app:layout_constraintEnd_toEndOf="parent"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
enter image description here
Try to set your navigation drawer item layout gravity. Example :
android:gravity="right"
Is this even possible? I created this view flipper and I am calling the view flipper from the onClick inside of the xml layout. I have created a view flipper before but for some reason it's not working.
<?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:cacheColorHint="#android:color/transparent"
android:orientation="vertical" >
<ViewFlipper
android:id="#+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:cacheColorHint="#android:color/transparent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vf_sample1_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#android:color/transparent"
android:orientation="vertical" >
<include layout="#layout/headers_main" />
<include layout="#layout/searchbar" />
<TextView
android:id="#+id/sdfsd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:maxHeight="85dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
onClick="gotoSomething"
android:singleLine="false" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/aquablue"
android:textSize="15dp"
android:textStyle="bold" />
<include layout="#layout/listview_item_row_now_playing_info" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/aquablue"
android:textSize="15dp"
android:textStyle="bold" />
<include layout="#layout/container_listview" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vf_sdfsdfadf"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#null"
android:cacheColorHint="#android:color/transparent"
android:orientation="vertical" >
<include layout="#layout/header_vf_asdfasdfadadafsd" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vf_adsfasdfadsfasd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#null"
android:cacheColorHint="#android:color/transparent"
android:orientation="vertical" >
</LinearLayout>
</ViewFlipper>
</LinearLayout>
code:
public class BeatSpotPrototypeActivity extends BaseListActivity {
private final String TAG = BeatSpotPrototypeActivity.class.getSimpleName();
private ApplicationStateManager mAppStateMananger = ApplicationStateManager.GetInstance();
private Context mCtx = null;
private boolean mIsInitalized = false;
private boolean mDataChanded= false;
private ViewFlipper mViewFlipper= null;
private DrawableManager mDrawManager = new DrawableManager();
private enum ViewFlipperModes {
MAIN (0),
NOW_PLAYING (1),
SONG_INFORMATION (2);
private final int index;
ViewFlipperModes(int index) {
this.index = index;
}
public int index() {
return index;
}
}
</code>
<code>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_beatspot_activity);
if (!mIsInitalized)
init();
else
mDataChanded = true;
showLoading(false);
}
private void init() {
mCtx = this;
mIsInitalized = true;
mViewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper);
fadeDrawables();
}
public void gotoBeatspotMain(View v) {
mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index());
}
public void gotoNowPlaying(View v) {
Log.d(TAG, mViewFlipper.getCurrentView().toString());
mViewFlipper.setDisplayedChild(ViewFlipperModes.NOW_PLAYING.index());
}
public void gotoSongDetails(View v) {
mViewFlipper.setDisplayedChild(ViewFlipperModes.SONG_INFORMATION.index());
Log.d(TAG, String.valueOf(ViewFlipperModes.SONG_INFORMATION.index()));
}
}
setDisplayedChild takes an index, not an id.
before on create
ViewFlipper mViewFlipper = (ViewFlipper)findViewbyId(location);
on your onCreate() or onStart
Ensure that whatever your layout on setcontentView(R.layout.something)
does contain the view flipper
Also try this for me. before this line mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index());
Type in:
int i = (ViewFlipperModes.MAIN.index()); place a debug point here
mViewFlipper.setDisplayedChild(i);
I also suggest using the debugger to try figure out if your flip views events are being called inside the debugger.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/book_as_whole_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<ViewFlipper
android:layout_marginTop="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ViewFlipper">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/page1"
android:text="#string/loading_string"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:typeface="serif"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/page2"
android:text="#string/loading_string"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:typeface="serif" />
</LinearLayout>
</ViewFlipper>
</LinearLayout>