第37篇 Android Studio实现点击图片显示信息(四)布局及资源文件
4.布局文件
整体是一个垂直布局,然后在设置一些水平布局就行了。
<LinearLayout 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:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/dormitory_information"
android:textSize="25sp"
/>
<RadioGroup
android:id="@+id/rgp_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbt_student1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@mipmap/background_player2"
android:text="@string/student_name_zhao"
android:background="@drawable/radiobutton_background_style"/>
<RadioButton
android:id="@+id/rbt_student2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:button="@null"
android:gravity="center"
android:layout_weight="1"
android:drawableTop="@mipmap/background_player2"
android:text="@string/student_name_wu"
android:background="@drawable/radiobutton_background_style"/>
<RadioButton
android:id="@+id/rbt_student3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@mipmap/background_player2"
android:text="@string/student_name_gong"
android:background="@drawable/radiobutton_background_style"/>
</RadioGroup>
<RadioGroup
android:id="@+id/rgp_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbt_student4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@mipmap/background_player2"
android:text="@string/student_name_chen"
android:background="@drawable/radiobutton_background_style"/>
<RadioButton
android:id="@+id/rbt_student5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@mipmap/background_player2"
android:text="@string/student"
android:background="@drawable/radiobutton_background_style"/>
<RadioButton
android:id="@+id/rbt_student6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:drawableTop="@mipmap/background_player2"
android:text="@string/student"
android:background="@drawable/radiobutton_background_style"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_information"
android:textSize="20sp"/>
<TextView
android:id="@+id/txt_student_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_name"/>
<TextView
android:id="@+id/txt_student_sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_sex"/>
<TextView
android:id="@+id/txt_student_ban"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_ban"/>
<TextView
android:id="@+id/txt_student_dormitory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_dormitory"/>
<TextView
android:id="@+id/txt_student_bed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_bed"/>
<TextView
android:id="@+id/txt_student_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/student_class"/>
</LinearLayout>
</LinearLayout>
我比较喜欢用LinearLyout布局,这个比较熟,而且自适应也比较好,所以用这个比较好。
4.1.strings.xml
<resources>
<string name="app_name">宿舍人员信息</string>
<string name="dormitory_information">宿舍人员名单</string>
<string name="student_name_zhao">张三</string>
<string name="student_name_wu">李四</string>
<string name="student_name_gong">王五</string>
<string name="student_name_chen">杨六</string>
<string name="student">学生</string>
<string name="student_information">学生信息</string>
<string name="student_name">姓名: </string>
<string name="student_sex">性别: </string>
<string name="student_ban">楼栋: </string>
<string name="student_dormitory">宿舍: </string>
<string name="student_bed">床号: </string>
<string name="student_class">班级: </string>
<string name="sex_man">男</string>
<string name="ban_number">6栋</string>
<string name="dormitory_number">506</string>
<string name="bed_number_1">1号</string>
<string name="bed_number_2">2号</string>
<string name="bed_number_3">3号</string>
<string name="bed_number_4">4号</string>
<string name="class_name">软工1903</string>
<string name="no_student">未添加</string>
</resources>