读书人

使用xml及java代码混同的方式来设置图

发布时间: 2013-10-27 15:21:50 作者: rapoo

使用xml及java代码混合的方式来设置图形界面

参考《疯狂android讲义》第2版2.1节

设置android的图形界面有三种方法:

1、使用纯xml文件

2、使用纯java,代码臃肿复杂,不建议使用

3、使用xml与java混合,前者用于固定基本不变的view,后者用于经常变化的view。


示例:使用xml+java,前者指定layout,后者指定一个imageView

MainAcitivity.java

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/root"    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"    tools:context=".MainActivity"    android:orientation="vertical" >        <ImageView         android:id="@+id/iv_books"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:contentDescription="@string/my_published_book"        /></LinearLayout>





读书人网 >图形图像

热点推荐