我需要在幻灯片抽屉菜单的底部添加按钮,但是如果我在xml上添加没有错误但是运行时它会显示错误
请帮我找出错误的地方
我想要这个: -
这是我的Xml: -
<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">
<RelativeLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/scr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/cscart"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/cscart" />
<TextView
android:id="@+id/border"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@+id/cscart"
android:background="#ffffff"/>
<Button
android:id="@+id/magento"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_below="@+id/border"
android:layout_centerHorizontal="true"
android:background="@drawable/magento" />
<TextView
android:id="@+id/border1"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@+id/magento"
android:background="#ffffff"/>
<Button
android:id="@+id/opencart"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_below="@+id/border1"
android:layout_centerHorizontal="true"
android:background="@drawable/opencart" />
<TextView
android:id="@+id/border2"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@+id/opencart"
android:background="#ffffff"/>
<TableLayout
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="170dp"
android:stretchColumns="1"
android:background="#ffffff"
android:layout_below="@+id/border2"
>
<TableRow>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:paddingRight="2dp">
<Button
android:id="@+id/abantecart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/abantecart" />
</FrameLayout>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:paddingLeft="2dp">
<Button
android:id="@+id/prestashop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/prestashop" />
</FrameLayout>
</TableRow>
</TableLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:layout_below="@+id/ll"
>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OUR NEWSLETTER"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="14sp"/>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_below="@+id/text1"
android:text="Subscribe To Our Newsletter And Be The First To Get Our Latest"
android:textColor="#000000"
android:textSize="10sp"/>
<LinearLayout
android:id="@+id/ll1"
android:layout_width="250dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/text2"
android:layout_marginTop="10dp"
android:background="@drawable/email_entry">
<EditText
android:id="@+id/mail_id"
android:layout_width="220dp"
android:layout_height="match_parent"
android:hint="Enter Your Email Address"
android:textSize="10sp"
android:inputType="textEmailAddress"/>
<Button
android:id="@+id/subscribe_mailid"
android:layout_width="32dp"
android:layout_height="match_parent"
android:background="#00000000"
/>
</LinearLayout>
<Button
android:id="@+id/guarenteed"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="@+id/ll1"
android:text="100% GUARENTEED"
android:textColor="#ababab"
android:background="@drawable/gurenteed_color"
android:textSize="12sp"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/border3"
android:layout_width="match_parent"
android:layout_height="0.1sp"
android:layout_below="@+id/guarenteed"
android:background="#ababab"/>
<Button
android:id="@+id/membership"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="@+id/border3"
android:text="OUR MEMBERSHIP"
android:textColor="#ababab"
android:background="@drawable/gurenteed_color"
android:textSize="12sp"
/>
<TextView
android:id="@+id/border4"
android:layout_width="match_parent"
android:layout_height="0.1sp"
android:layout_below="@+id/membership"
android:background="#ababab"/>
<Button
android:id="@+id/secure_payment"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="@+id/border4"
android:text="100% SECURE PAYMENT"
android:textColor="#ababab"
android:background="@drawable/gurenteed_color"
android:textSize="12sp"
/>
<TextView
android:id="@+id/border5"
android:layout_width="match_parent"
android:layout_height="0.1sp"
android:layout_below="@+id/secure_payment"
android:background="#ababab"/>
<Button
android:id="@+id/forum_access"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="@+id/border5"
android:text="24X7 FORUM ACCESS"
android:textColor="#ababab"
android:background="@drawable/gurenteed_color"
android:textSize="12sp"
/>
<TextView
android:id="@+id/border6"
android:layout_width="match_parent"
android:layout_height="0.1sp"
android:layout_below="@+id/forum_access"
android:background="#ababab"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3a3439"
android:layout_below="@+id/border6"
android:layout_centerHorizontal="true">
<LinearLayout
android:id="@+id/ll2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
>
<Button
android:id="@+id/facebook"
android:layout_width="50dp"
android:layout_height="20dp"
android:background="@drawable/facebook"
android:layout_marginRight="5dp"/>
<Button
android:id="@+id/twitter"
android:layout_width="50dp"
android:layout_height="20dp"
android:background="@drawable/twitter"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<TextView
android:id="@+id/link"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/link_add"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_below="@+id/ll2"/>
<TextView
android:layout_width="310dp"
android:layout_height="wrap_content"
android:background="@drawable/copyright"
android:layout_centerHorizontal="true"
android:layout_below="@+id/link"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start">
<!-- Listview to display slider menu -->
<ExpandableListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector"
android:background="@drawable/slidemenu_back"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text="b1"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text="b1"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text="b1"/>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
主要活动: -
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
//private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
public static int cart;
static boolean read=true;
InputStream is=null;
String result=null;
String line=null;
String mail_id;
int code;
static boolean changebackground=true;
//expandable listview
ExpandableListAdapter listAdapter;
ExpandableListView mDrawerList;;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
//expandable listview
TextView totalitems;
DatabaseHandler data;
ImageView gotocart;
List<String> OurTemplates;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
changebackground=false;
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(
R.layout.actionbar,
null);
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT);
// Set up your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
actionBarLayout.setLayoutParams(lp);
Button menu=(Button) actionBarLayout.findViewById(R.id.menu);
totalitems=(TextView) actionBarLayout.findViewById(R.id.detail_totalcartitem);
data=new DatabaseHandler(getApplicationContext());
mTitle = mDrawerTitle = getTitle();
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
mDrawerList = (ExpandableListView) findViewById(R.id.list_slidermenu);
mDrawerList.setGroupIndicator(null);
prepareListData();
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1), true, ""));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(7, -1)));
// Recycle the typed array
navMenuIcons.recycle();
//expandable listview
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
mDrawerList.setAdapter(listAdapter);
// Listview Group click listener
mDrawerList.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview Group expanded listener
mDrawerList.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
/*Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();*/
}
});
// Listview Group collasped listener
mDrawerList.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
/* Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();*/
}
});
// Listview on child click listener
mDrawerList.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
/
int pos=childPosition;
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
changebackground=true;
if(pos==0)
{
// Adding child data
listDataHeader.add("E-commerce Templates");
// Adding child data
List<String> E_commerce = new ArrayList<String>();
E_commerce.add("Cs-Cart");
E_commerce.add("Magento");
E_commerce.add("Opencart");
E_commerce.add("Prestashop");
E_commerce.add("Abantecart");
listDataChild.put(listDataHeader.get(0), E_commerce);
listAdapter = new ExpandableListAdapter(MainActivity.this, listDataHeader, listDataChild);
// setting list adapter
mDrawerList.setAdapter(listAdapter);
mDrawerList.expandGroup(0, true);
}
else if(pos==1)
{
listDataHeader.add("CMS Templates");
List<String> CMS = new ArrayList<String>();
CMS.add("Wordpress");
CMS.add("Drupal");
listDataChild.put(listDataHeader.get(0), CMS);
listAdapter = new ExpandableListAdapter(MainActivity.this, listDataHeader, listDataChild);
mDrawerList.setAdapter(listAdapter);
mDrawerList.expandGroup(0, true);
}
else if(pos==2)
{
listDataHeader.add("Video Sharing Templates");
List<String> video_sharing = new ArrayList<String>();
video_sharing.add("Clipshare");
video_sharing.add("Phpmotion");
listDataChild.put(listDataHeader.get(0), video_sharing);
listAdapter = new ExpandableListAdapter(MainActivity.this, listDataHeader, listDataChild);
mDrawerList.setAdapter(listAdapter);
mDrawerList.expandGroup(0, true);
}
else if(pos==3)
{
listDataHeader.add("Social Networking Templates");
List<String> social_networking = new ArrayList<String>();
social_networking.add("Dolphin");
social_networking.add("Socialengine");
listDataChild.put(listDataHeader.get(0), social_networking);
listAdapter = new ExpandableListAdapter(MainActivity.this, listDataHeader, listDataChild);
mDrawerList.setAdapter(listAdapter);
mDrawerList.expandGroup(0, true);
}
else if(pos==4)
{
listDataHeader.add("Free Templates");
List<String> free_templates = new ArrayList<String>();
free_templates.add("Cs-Cart");
free_templates.add("Magento");
free_templates.add("Opencart");
free_templates.add("Prestashop");
free_templates.add("Dolphine");
free_templates.add("Drupal");
listDataChild.put(listDataHeader.get(0), free_templates);
listAdapter = new ExpandableListAdapter(MainActivity.this, listDataHeader, listDataChild);
mDrawerList.setAdapter(listAdapter);
mDrawerList.expandGroup(0, true);
}
return false;
}
});
;
menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.openDrawer(mDrawerList);
}
else if (mDrawerLayout.isDrawerOpen(mDrawerList)){
mDrawerLayout.closeDrawer(mDrawerList);
}
}
});
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer,
R.string.app_name,
R.string.app_name
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("E-commerce Templates");
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
displayView(0);
}
}
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
displayView(position);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
return super.onPrepareOptionsMenu(menu);
}
private void displayView(int position) {
switch (position) {
case 0:
//fragment = new Home();
// click();
///mDrawerLayout.closeDrawer(mDrawerList);
break;
case 1:
Intent i=new Intent(MainActivity.this, CsCart.class);
startActivity(i);
break;
case 2:
click();
break;
case 3:
click();
break;
case 4:
click();
break;
case 5:
click();
break;
default:
break;
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
void click()
{
navDrawerItems.clear();
}
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Home");
listDataHeader.add("Our Templates");
listDataHeader.add("Our Services");
listDataHeader.add("Portfolio");
listDataHeader.add("Add-ons");
listDataHeader.add("Blog");
listDataHeader.add("Forum");
listDataHeader.add("Contact us");
// Adding child data
OurTemplates = new ArrayList<String>();
OurTemplates.add("E-commerce Templates");
OurTemplates.add("CMS Templates");
OurTemplates.add("Video Sharing Templates");
OurTemplates.add("Social Networking Templates");
OurTemplates.add("Free Templates");
listDataChild.put(listDataHeader.get(0),new ArrayList<String>() );
listDataChild.put(listDataHeader.get(1), OurTemplates);
listDataChild.put(listDataHeader.get(2), new ArrayList<String>());
listDataChild.put(listDataHeader.get(3), new ArrayList<String>());
listDataChild.put(listDataHeader.get(4), new ArrayList<String>());
listDataChild.put(listDataHeader.get(5), new ArrayList<String>());
listDataChild.put(listDataHeader.get(6), new ArrayList<String>());
listDataChild.put(listDataHeader.get(7), new ArrayList<String>());// Header, Child data
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
}
在运行时我收到这样的错误
04-16 02:59:47.594: E/AndroidRuntime(1086): FATAL EXCEPTION: main
04-16 02:59:47.594: E/AndroidRuntime(1086): Process: com.bugtreat.shopping, PID: 1086
04-16 02:59:47.594: E/AndroidRuntime(1086): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:844)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.support.v4.widget.DrawerLayout.isDrawerOpen(DrawerLayout.java:1096)
04-16 02:59:47.594: E/AndroidRuntime(1086): at com.bugtreat.shopping.MainActivity.onPrepareOptionsMenu(MainActivity.java:586)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.app.Activity.onPreparePanel(Activity.java:2556)
04-16 02:59:47.594: E/AndroidRuntime(1086): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:464)
04-16 02:59:47.594: E/AndroidRuntime(1086): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
04-16 02:59:47.594: E/AndroidRuntime(1086): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.view.Choreographer.doFrame(Choreographer.java:543)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.os.Handler.handleCallback(Handler.java:733)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.os.Handler.dispatchMessage(Handler.java:95)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.os.Looper.loop(Looper.java:136)
04-16 02:59:47.594: E/AndroidRuntime(1086): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-16 02:59:47.594: E/AndroidRuntime(1086): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 02:59:47.594: E/AndroidRuntime(1086): at java.lang.reflect.Method.invoke(Method.java:515)
04-16 02:59:47.594: E/AndroidRuntime(1086): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-16 02:59:47.594: E/AndroidRuntime(1086): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-16 02:59:47.594: E/AndroidRuntime(1086): at dalvik.system.NativeStart.main(Native Method)