多界面调用统一导航菜单栏问题……求大神帮忙

msdzysj 2014-12-08 11:42:51
想做多个界面
在页面最下方引入一个统一的导航菜单
百度上找了很多看不太懂
大多都是写某个界面里的菜单
我想弄成统一的一个
在页面布局和页面activity里直接调用加载的
activity里的有点思路
直接写个公用方法
但是加载页面的不会
有没有帮忙的大神
...全文
252 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2014-12-08
  • 打赏
  • 举报
回复
引用 3 楼 msdzysj 的回复:
[quote=引用 2 楼 WantD 的回复:] 写一个自定义的view,然后再其他页面用的的时候像引用其他系统控件一样用就可以了
能帮忙写下具体点的代码么? 新手不知道怎么写[/quote] 在layout中把布局布好(R.layout.widget_title),然后定一个类似这样的TitleView,然后在其他页面需要用到这个 导航菜单 的时候 直接 <com.xx.TitleView> </com.xx.TitleView> 这样引用

public class TitleView extends RelativeLayout {
	
	//可以在此定义一些interface或者之类的满足不同页面的需求

	private void initView(Context context) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.widget_title, this);

		//在这里对 布局文件的 控件 定义相关事件

		
	}
	
	
}

msdzysj 2014-12-08
  • 打赏
  • 举报
回复
引用 1 楼 bdmh 的回复:
一个就够了,主activity中下方一个导航,上面放一个容器,其他页面都显示在这个容器里
通过下方的导航 控制上面的容器加载的内容?
msdzysj 2014-12-08
  • 打赏
  • 举报
回复
引用 2 楼 WantD 的回复:
写一个自定义的view,然后再其他页面用的的时候像引用其他系统控件一样用就可以了
能帮忙写下具体点的代码么? 新手不知道怎么写
「已注销」 2014-12-08
  • 打赏
  • 举报
回复
写一个自定义的view,然后再其他页面用的的时候像引用其他系统控件一样用就可以了
bdmh 2014-12-08
  • 打赏
  • 举报
回复
一个就够了,主activity中下方一个导航,上面放一个容器,其他页面都显示在这个容器里
「已注销」 2014-12-08
  • 打赏
  • 举报
回复
现在有点闲就帮你搞下:378434243
msdzysj 2014-12-08
  • 打赏
  • 举报
回复
引用 8 楼 WantD 的回复:
还有titleView 里面不需要再添加控件之类的了,既然是要 满足 重用 就应该在 TitleView 的layout里面把需要到的控件先布局好。再具体页面用的时候看情况 View.visible或者View.invisible




能说不明白吗?
有QQ么……
这样好麻烦啊
「已注销」 2014-12-08
  • 打赏
  • 举报
回复
还有titleView 里面不需要再添加控件之类的了,既然是要 满足 重用 就应该在 TitleView 的layout里面把需要到的控件先布局好。再具体页面用的时候看情况 View.visible或者View.invisible
「已注销」 2014-12-08
  • 打赏
  • 举报
回复
引用 6 楼 msdzysj 的回复:
[quote=引用 5 楼 WantD 的回复:] [quote=引用 3 楼 msdzysj 的回复:] [quote=引用 2 楼 WantD 的回复:] 写一个自定义的view,然后再其他页面用的的时候像引用其他系统控件一样用就可以了
能帮忙写下具体点的代码么? 新手不知道怎么写[/quote] 在layout中把布局布好(R.layout.widget_title),然后定一个类似这样的TitleView,然后在其他页面需要用到这个 导航菜单 的时候 直接 <com.xx.TitleView> </com.xx.TitleView> 这样引用

public class TitleView extends RelativeLayout {
	
	//可以在此定义一些interface或者之类的满足不同页面的需求

	private void initView(Context context) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.widget_title, this);

		//在这里对 布局文件的 控件 定义相关事件

		
	}
	
	
}

[/quote] 额 思路明白了 但是具体怎么做一点没看懂 我建了布局XML
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"  >

    
   <TitleView
        android:id="@+id/MEMU_BAR_LINEAR_LAYOUT"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true" >

        <ImageButton
            android:id="@+id/HOME_BUTTON"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:background="#00ffffff"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_home"
            android:contentDescription="@string/HOME_BUTTON" />

        <ImageButton
            android:id="@+id/SEARCH_BUTTON"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:background="#00ffffff"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_search"
            android:contentDescription="@string/SEARCH_BUTTON" />
             </TitleView> 
</RelativeLayout>
然后eclipse 提示 Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup Exception details are logged in Window > Show View > Error Log The following classes could not be found: - TitleView (Fix Build Path, Edit XML) 这时候我是不是要创建TitleView 类?[/quote]
引用 6 楼 msdzysj 的回复:
[quote=引用 5 楼 WantD 的回复:] [quote=引用 3 楼 msdzysj 的回复:] [quote=引用 2 楼 WantD 的回复:] 写一个自定义的view,然后再其他页面用的的时候像引用其他系统控件一样用就可以了
能帮忙写下具体点的代码么? 新手不知道怎么写[/quote] 在layout中把布局布好(R.layout.widget_title),然后定一个类似这样的TitleView,然后在其他页面需要用到这个 导航菜单 的时候 直接 <com.xx.TitleView> </com.xx.TitleView> 这样引用

public class TitleView extends RelativeLayout {
	
	//可以在此定义一些interface或者之类的满足不同页面的需求

	private void initView(Context context) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.widget_title, this);

		//在这里对 布局文件的 控件 定义相关事件

		
	}
	
	
}

[/quote] 额 思路明白了 但是具体怎么做一点没看懂 我建了布局XML
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"  >

    
   <TitleView
        android:id="@+id/MEMU_BAR_LINEAR_LAYOUT"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true" >

        <ImageButton
            android:id="@+id/HOME_BUTTON"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:background="#00ffffff"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_home"
            android:contentDescription="@string/HOME_BUTTON" />

        <ImageButton
            android:id="@+id/SEARCH_BUTTON"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:background="#00ffffff"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_search"
            android:contentDescription="@string/SEARCH_BUTTON" />
             </TitleView> 
</RelativeLayout>
然后eclipse 提示 Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup Exception details are logged in Window > Show View > Error Log The following classes could not be found: - TitleView (Fix Build Path, Edit XML) 这时候我是不是要创建TitleView 类?[/quote] 你自定义view的路径引用不对 com.xx.TitleView前面的 com.xx. 是你的TitileView所在的package路径,要引用完全 不然会出现 class could not found
msdzysj 2014-12-08
  • 打赏
  • 举报
回复
引用 5 楼 WantD 的回复:
[quote=引用 3 楼 msdzysj 的回复:]
[quote=引用 2 楼 WantD 的回复:]
写一个自定义的view,然后再其他页面用的的时候像引用其他系统控件一样用就可以了

能帮忙写下具体点的代码么?
新手不知道怎么写[/quote]

在layout中把布局布好(R.layout.widget_title),然后定一个类似这样的TitleView,然后在其他页面需要用到这个 导航菜单 的时候 直接

<com.xx.TitleView> </com.xx.TitleView>
这样引用

public class TitleView extends RelativeLayout {

//可以在此定义一些interface或者之类的满足不同页面的需求

private void initView(Context context) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.widget_title, this);

//在这里对 布局文件的 控件 定义相关事件


}


}

[/quote]


思路明白了
但是具体怎么做一点没看懂



我建了布局XML
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >


<TitleView
android:id="@+id/MEMU_BAR_LINEAR_LAYOUT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >

<ImageButton
android:id="@+id/HOME_BUTTON"
android:layout_width="60dip"
android:layout_height="60dip"
android:background="#00ffffff"
android:scaleType="centerCrop"
android:src="@drawable/ic_home"
android:contentDescription="@string/HOME_BUTTON" />

<ImageButton
android:id="@+id/SEARCH_BUTTON"
android:layout_width="60dip"
android:layout_height="60dip"
android:background="#00ffffff"
android:scaleType="centerCrop"
android:src="@drawable/ic_search"
android:contentDescription="@string/SEARCH_BUTTON" />
</TitleView>
</RelativeLayout>


然后eclipse 提示
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- TitleView (Fix Build Path, Edit XML)


这时候我是不是要创建TitleView 类?

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧