安卓标签栏问题
在我的 Android 应用程序中,我有 10 个布局和一个带有 4 个按钮的选项卡栏。对于这 4 个按钮,我有 4 种不同的布局。在我的应用程序中,我想将选项卡栏放置在应用程序的底部,并且我想在所有 10 种布局中显示选项卡栏。所以我使用 view
方法设计了布局。我的布局似乎如下所示
<?xml version="1.0" encoding="utf-8" ?>
<view xmlns:android="http://schemas.android.com/apk/res/android" class="com.sample.app.TabBar$iRelativeLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/TabLayout_One" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Home Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_two" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Add Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_three" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Search Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_four" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Help Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_five" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="SignIn Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_six" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="signUp Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_seven" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Profile Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_eight" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Map Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_Nine" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="ListView Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_Ten" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Home Screen"/>
</RelativeLayout>
<view class="com.resting.spot.TabBar$iTab" android:id="@+id/Tabs" android:layout_width="fill_parent" android:layout_height="50px" android:layout_alignParentBottom="true" />
</view>
上面是我的布局,在我的编码部分中,我曾经将特定布局设为 view.VISIBLE
,将所有其他布局设为 view.GONE
> 如下
private static final int TAB_HOME = 1;
private static final int TAB_ADD = 2;
private static final int TAB_SCH = 3;
private static final int TAB_HELP = 4;
private iTab mTabs;
private RelativeLayout mTabLayout_One;
private RelativeLayout mTabLayout_Two;
private RelativeLayout mTabLayout_Three;
private RelativeLayout mTabLayout_Four;
private RelativeLayout mTabLayout_Five;
private RelativeLayout mTabLayout_Six;
private RelativeLayout mTabLayout_Seven;
private RelativeLayout mTabLayout_Eight;
private RelativeLayout mTabLayout_Nine;
private RelativeLayout mTabLayout_ten;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbar);
mTabs = (iTab) this.findViewById( R.id.Tabs );
mTabLayout_One=(RelativeLayout)findViewById(R.id.TabLayout_One);
mTabLayout_Two=(RelativeLayout)findViewById( R.id.TabLayout_two );
mTabLayout_Three = (RelativeLayout) this.findViewById( R.id.TabLayout_three );
mTabLayout_Four = (RelativeLayout) this.findViewById( R.id.TabLayout_four );
mTabLayout_Five = (RelativeLayout) this.findViewById( R.id.TabLayout_five );
mTabLayout_Six = (RelativeLayout) this.findViewById( R.id.TabLayout_six);
mTabLayout_Seven = (RelativeLayout) this.findViewById( R.id.TabLayout_seven);
mTabLayout_Eight = (RelativeLayout) this.findViewById( R.id.TabLayout_eight);
mTabLayout_Nine = (RelativeLayout) this.findViewById( R.id.TabLayout_nine);
mTabs.addTabMember( new TabMember( TAB_HOME, "", R.drawable.home ));
mTabs.addTabMember( new TabMember( TAB_ADD , "", R.drawable.add ) );
mTabs.addTabMember( new TabMember( TAB_SCH , "", R.drawable.search ) );
mTabs.addTabMember( new TabMember( TAB_HELP, "", R.drawable.help ) );
mTabLayout_One.setVisibility( View.VISIBLE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.GONE ); mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
mTabs.setOnTabClickListener( new OnTabClickListener()
{
public void onTabClick( int tabId )
{
if( tabId == TAB_HOME )
{
mTabLayout_One.setVisibility( View.VISIBLE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.GONE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
else if( tabId == TAB_ADD )
{
mTabLayout_One.setVisibility( View.GONE );
mTabLayout_Two.setVisibility( View.VISIBLE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.GONE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
else if( tabId == TAB_SCH )
{
mTabLayout_One.setVisibility( View.GONE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.VISIBLE );
mTabLayout_Four.setVisibility( View.GONE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
else if( tabId == TAB_HELP )
{
mTabLayout_One.setVisibility( View.GONE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.VISIBLE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
}
});
}
}
现在问题是对于每个relativelayout我曾经有大约4个按钮和10个编辑框。在我的应用程序中,我只有一门活动课程。我是否应该在一个类中声明所有这些函数,并且必须在一个类中编写所有功能。在这种情况下,我的代码行会超过大约 2000 行,如果它在任何地方崩溃,我会很困惑。
有没有办法为所有相关布局创建一个单独的类,在其中我可以声明按钮及其 id 以及所有功能,例如 uploadind 和将数据下载到服务器
或任何其他解决方案,请帮助我。我对 android 和编程完全陌生,请帮助我,很抱歉问了这么长的问题......
in my android app i have 10 layouts and a tabbar with 4 buttons in it. For this 4 buttons i have 4 different layouts. In my app i want to place the tab bar at the bottom of the app and i want to show the tabbar in all the 10 layouts. So i designed the layout using the view
method. My layout seems to be as follows
<?xml version="1.0" encoding="utf-8" ?>
<view xmlns:android="http://schemas.android.com/apk/res/android" class="com.sample.app.TabBar$iRelativeLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/TabLayout_One" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Home Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_two" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Add Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_three" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Search Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_four" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Help Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_five" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="SignIn Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_six" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="signUp Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_seven" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Profile Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_eight" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Map Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_Nine" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="ListView Screen"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/TabLayout_Ten" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#f5f5f5" android:text="Home Screen"/>
</RelativeLayout>
<view class="com.resting.spot.TabBar$iTab" android:id="@+id/Tabs" android:layout_width="fill_parent" android:layout_height="50px" android:layout_alignParentBottom="true" />
</view>
Above is my layout and in my coding part, i used to make the particular layout to be view.VISIBLE
and all other to be view.GONE
as follows
private static final int TAB_HOME = 1;
private static final int TAB_ADD = 2;
private static final int TAB_SCH = 3;
private static final int TAB_HELP = 4;
private iTab mTabs;
private RelativeLayout mTabLayout_One;
private RelativeLayout mTabLayout_Two;
private RelativeLayout mTabLayout_Three;
private RelativeLayout mTabLayout_Four;
private RelativeLayout mTabLayout_Five;
private RelativeLayout mTabLayout_Six;
private RelativeLayout mTabLayout_Seven;
private RelativeLayout mTabLayout_Eight;
private RelativeLayout mTabLayout_Nine;
private RelativeLayout mTabLayout_ten;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbar);
mTabs = (iTab) this.findViewById( R.id.Tabs );
mTabLayout_One=(RelativeLayout)findViewById(R.id.TabLayout_One);
mTabLayout_Two=(RelativeLayout)findViewById( R.id.TabLayout_two );
mTabLayout_Three = (RelativeLayout) this.findViewById( R.id.TabLayout_three );
mTabLayout_Four = (RelativeLayout) this.findViewById( R.id.TabLayout_four );
mTabLayout_Five = (RelativeLayout) this.findViewById( R.id.TabLayout_five );
mTabLayout_Six = (RelativeLayout) this.findViewById( R.id.TabLayout_six);
mTabLayout_Seven = (RelativeLayout) this.findViewById( R.id.TabLayout_seven);
mTabLayout_Eight = (RelativeLayout) this.findViewById( R.id.TabLayout_eight);
mTabLayout_Nine = (RelativeLayout) this.findViewById( R.id.TabLayout_nine);
mTabs.addTabMember( new TabMember( TAB_HOME, "", R.drawable.home ));
mTabs.addTabMember( new TabMember( TAB_ADD , "", R.drawable.add ) );
mTabs.addTabMember( new TabMember( TAB_SCH , "", R.drawable.search ) );
mTabs.addTabMember( new TabMember( TAB_HELP, "", R.drawable.help ) );
mTabLayout_One.setVisibility( View.VISIBLE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.GONE ); mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
mTabs.setOnTabClickListener( new OnTabClickListener()
{
public void onTabClick( int tabId )
{
if( tabId == TAB_HOME )
{
mTabLayout_One.setVisibility( View.VISIBLE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.GONE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
else if( tabId == TAB_ADD )
{
mTabLayout_One.setVisibility( View.GONE );
mTabLayout_Two.setVisibility( View.VISIBLE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.GONE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
else if( tabId == TAB_SCH )
{
mTabLayout_One.setVisibility( View.GONE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.VISIBLE );
mTabLayout_Four.setVisibility( View.GONE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
else if( tabId == TAB_HELP )
{
mTabLayout_One.setVisibility( View.GONE );
mTabLayout_Two.setVisibility( View.GONE );
mTabLayout_Three.setVisibility( View.GONE );
mTabLayout_Four.setVisibility( View.VISIBLE );
mTabLayout_Five.setVisibility( View.GONE );
mTabLayout_Six.setVisibility( View.GONE );
mTabLayout_Seven.setVisibility( View.GONE );
mTabLayout_Eight.setVisibility( View.GONE );
mTabLayout_Nine.setVisibility( View.GONE );
}
}
});
}
}
Now the problem is for each Relativelayout i used to have around 4 buttons and 10 edit boxes. In my app i have only one activity class. Should i have to declare all these functions in a single class and i have to write all functionality in a single class. In such a case my code line gets exceeded around 2000 lines and if it get crashed anywhere i am getting confused a lot.
is there any way to create a separate class for all the relative layouts where i can declare the buttons and their ids and all functionality such as uploadind and downloading data to server
or any other solution, please help me. i am entirely new to android and programming please help me and sorry for such a long question....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论