首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Android 登錄頁面底部「第三方登錄」區域的 XML 布局實現

     編輯:程式設計綜合問答

視覺拆解

典型「第三方登錄」區域:一行文字(如「其他方式登錄」)居中,下方三個圖標按鈕(微信、QQ、微博)等寬分佈,底部留白。

推薦布局:LinearLayout + layout_weight

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:padding="16dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="其他方式登錄"
        android:textColor="#999999"
        android:textSize="14sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="12dp"
        android:gravity="center">

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_wechat"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="微信登錄" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_qq"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="QQ登錄" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_weibo"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="微博登錄" />

    </LinearLayout>
</LinearLayout>

關鍵屬性解析

  • layout_width="0dp" + layout_weight="1":三個按鈕**等寬佔滿父容器**,自適應螢幕寬度。
  • background="?attr/selectableItemBackgroundBorderless"`:點擊回饋波紋效果,無邊框干擾。
  • contentDescription:無障礙支持,通過無障礙掃描。

進階:使用 ConstraintLayout (API 9+)

若項目已遷移至 ConstraintLayout,可用 `app:layout_constraintHorizontal_chainStyle="spread_inside"` 實現鏈式等寬分佈,層級更扁平。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved