Android编程权威指南 - 第8章 使用布局与组件创建用户界

2016-11-22  本文已影响61人  JMasche

新界面代码

更新fragment_crime.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="wrap_content"    
      android:orientation="vertical">        
      <TextView        
            android:layout_width="match_parent"        
            android:layout_height="match_parent"        
            android:text="@string/crime_title_label"        
            style="?android:listSeparatorTextViewStyle"        
            />    
      <EditText        
            android:id="@+id/crime_title"        
            android:layout_width="match_parent"        
            android:layout_height="wrap_content"        
            android:layout_marginLeft="16dp"        
            android:layout_marginRight="16dp"        
            android:hint="@string/crime_title_hint" />    
      <TextView        
            android:layout_width="match_parent"        
            android:layout_height="wrap_content"        
            android:text="@string/crime_details_label"        
            style="?android:listSeparatorTextViewStyle"        
            />        
      <Button        
            android:id="@+id/crime_date"        
            android:layout_width="match_parent"        
            android:layout_height="wrap_content"        
            android:layout_marginLeft="16dp"        
            android:layout_marginRight="16dp" />    
      <CheckBox        
            android:id="@+id/crime_solved"        
            android:layout_width="match_parent"        
            android:layout_height="wrap_content"        
            android:layout_marginLeft="16dp"        
            android:layout_marginRight="16dp"        
            android:text="@string/crime_solved_label"/>
</LinearLayout>

更新CrimeFragment.java

mDateButton = (Button)v.findViewById(R.id.crime_date);
mDateButton.setText(mCrime.getDate().toString());
mDateButton.setEnabled(false);
mSolvedCheckBox = (CheckBox)v.findViewById(R.id.crime_solved);
mSolvedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){    
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {        
            mCrime.setSolved(isChecked);    
      }
});

深入探讨XML布局属性

样式、主题及主题属性

<style name="BigTextStyle">
      <item name="android:textSize">20sp</item>
      <item name="android:layout_margin">3dp</item>
</style>

dp、sp以及屏幕像素密度

LinearLayout标签内容

上一篇 下一篇

猜你喜欢

热点阅读