iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 28
0
自我挑戰組

向Android APP開發說Hello系列 第 28

Day 28. 改善List item外觀

今天來做一些有關介面外觀改善的練習。
在手機上我們可以打開輔助線來看每個view的界限,
路徑在:設定 > 系統 > 開發人員選項 > 顯示版面配置界限
https://ithelp.ithome.com.tw/upload/images/20181112/20107569GRbcWyudcI.png

順便看一下目前的版面,逐一修改的項目如下:

1.各個List item的內邊距

開啟list_item.xml,設定各list item至少高88dp(可以更高,不能再低)。
android:minHeight="88dp"
https://ithelp.ithome.com.tw/upload/images/20181112/20107569g7SII2Y4I3.png

2.各個List item的顏色與文字設定

打開colors.xml(路徑在app/res/values/colors.xml),加上我們所需的顏色

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#193a37</color>
    <color name="colorPrimaryDark">#1d302e</color>
    <color name="colorAccent">#D81B60</color>
    <color name="colorTortoise">#6c7a75</color>
    <color name="colorBackground">#57635f</color>
</resources>

再到list_item.xml做以下更動:

  • 外層LinearLayout
    1. 補上背景色設定:android:background="@color/colorBackground"
  • 在ImageView裡將圖片也設為最小高度:android:layout_height="88dp"
  • 內層LinearLayout
    1. LinearLayout的android:background="@color/colorTortoise"
  • 對兩個TextView設定
    1. 設定字型大小:tools:textAppearance="?android:textAppearanceMedium"
    2. 設定字型顏色:android:textColor="@android:color/white"
    3. 讓文字垂直置中:android:layout_height="0dp",並設定android:layout_weight="1"
    4. android:gravity="bottom" 以及 android:gravity="top"
  • TIP:有關android:layout_weight的使用,可參考Day 4. VIEWS - ViewGroups (part.2)
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
    android:orientation="horizontal"
    android:paddingLeft="16dp"
    android:minHeight="88dp"
    android:background="@color/colorBackground">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="88dp"
        android:paddingRight="16dp"/>

    <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:paddingLeft="16dp"
        android:background="@color/colorTortoise">

        <TextView
            android:id="@+id/tortoises_text_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="bottom"
            tools:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/default_text_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="top"
            tools:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white"/>
    </LinearLayout>

</LinearLayout>

最後來個比較:
https://ithelp.ithome.com.tw/upload/images/20181112/20107569sRFs7bGT15.png


上一篇
Day 27. 在自訂Layout加入圖片
下一篇
Day 29. Android資料儲存-SQLite (part 1)
系列文
向Android APP開發說Hello30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言