Android高级界面设计2

来源:互联网 发布:大数据平台对比分析 编辑:程序博客网 时间:2024/05/22 20:32

1.选项卡

activity_main.xml 中

 <TabHost xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@android:id/tabhost"        android:layout_width="match_parent"        android:layout_height="match_parent"        >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical" >            <TabWidget                android:id="@android:id/tabs"                android:layout_width="fill_parent"                android:layout_height="wrap_content" >            </TabWidget>            <FrameLayout                android:id="@android:id/tabcontent"                android:layout_width="match_parent"                android:layout_height="match_parent" >            </FrameLayout>        </LinearLayout>    </TabHost>

添加文件 tab.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="match_parent"    android:orientation="vertical"    android:id="@+id/linearLayout01" >    <TextView               android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="123456" />    <TextView              android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="456789" /></LinearLayout>

添加文件tab1.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="match_parent"    android:orientation="vertical"    android:id="@+id/linearLayout02" >    <TextView               android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="asdfgh" />    <TextView              android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="zxcvbn" /></LinearLayout>


MainActivity.java 中

public class MainActivity extends Activity {private TabHost tabhost=null; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tabhost = (TabHost)findViewById(android.R.id.tabhost);tabhost.setup();LayoutInflater inflater = LayoutInflater.from(this);inflater.inflate(R.layout.tab, tabhost.getTabContentView());inflater.inflate(R.layout.tab1, tabhost.getTabContentView());tabhost.addTab(tabhost.newTabSpec("tab").setIndicator("未接来电").setContent(R.id.linearLayout01));//添加第一个标签页tabhost.addTab(tabhost.newTabSpec("tab1").setIndicator("已接来电").setContent(R.id.linearLayout02));//添加第二个标签页}}

2.图片浏览器

   点击   https://github.com/Caption-He/android_picture_wall

原创粉丝点击