Android:weight,margin,padding詳解實例

来源:https://www.cnblogs.com/dashucoding/archive/2018/08/19/9499649.html
-Advertisement-
Play Games

weight詳解 是用來等比例劃分區域的屬性。 案例代碼 為什麼出現2:1的案例呢?three怎麼就不見了呢? 1. 每個寬度為 ,屏幕為1,那麼屏幕就是1 3= 2個 2. 計算方法, ,結果是one占了兩份,two占了一份,three什麼都沒有 ,`padding`詳解 代表是偏移,表示組件離容 ...


標題圖

weight詳解

weight是用來等比例劃分區域的屬性。

案例代碼

dashucoding

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="math_parent"
android:background="#ADFF2F"
android:layout_weight="1"/>

<LinearLayout
android:layout_width="0dp"
android:layout_height="math_parent"
android:background="#DA70D6"
android:layout_weight="2"/>

</LinearLayout>

dashucoding

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="math_parent"
android:background="#ADFF2F"
android:layout_weight="1"/>

<LinearLayout
android:layout_width="0dp"
android:layout_height="math_parent"
android:background="#DA70D6"
android:layout_weight="1"/>

</LinearLayout>

dashucoding

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/LinearLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" >

  <TextView
  android:layout_weight="1"
  android:layout_width="wrap_content"
  android:layout_height="math_parent"
  android:text="one"
  android:background="#98FB98"
  />
  <TextView
  android:layout_weight="2"
  android:layout_width="wrap_content"
  android:layout_height="math_parent"
  android:text="two"
  android:background="#FFFF00"
 />
 <TextView
 android:layout_weight="3"
 android:layout_width="wrap_content"
 android:layout_height="math_parent"  
 android:text="three"
 android:background="#FF00FF"
 />

</LinearLayout>

dashucoding

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/LinearLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" >

  <TextView
  android:layout_weight="1"
  android:layout_width="math_parent"
  android:layout_height="math_parent"
  android:text="one"
  android:background="#98FB98"
  />
  <TextView
  android:layout_weight="2"
  android:layout_width="math_parent"
  android:layout_height="math_parent"
  android:text="two"
  android:background="#FFFF00"
 />
 <TextView
 android:layout_weight="3"
 android:layout_width="math_parent"
 android:layout_height="math_parent"  
 android:text="three"
 android:background="#FF00FF"
 />

</LinearLayout>

為什麼出現2:1的案例呢?three怎麼就不見了呢?

  1. 每個寬度為math_parent,屏幕為1,那麼屏幕就是1-3=-2個math_parent
  2. 計算方法,1 - 2 * (1/6) = 2/3,1 - 2 * (2/6) = 1/3, 1 - 2 * (3/6) = 0,結果是one占了兩份,two占了一份,three什麼都沒有

marginpadding詳解

margin代表是偏移,表示組件離容器偏移量,margin針對的是容器中的組件元素;padding代表是填充,填充的對象針對的是組件中的元素。

<RelativeLayout
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">

  <Button
  android:id="@+id/btn1"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:text="Button"/>
  <Button
  android:paddingLeft="100dp"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:text="Button"
  android:layout_toRightOf="@id/btn1"/>

  <Button
  android:id="@+id/btn2"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:text="Button"
  android:layout_alignParentBottom="true"/>
  <Button
  android:layout_marginLeft="100dp"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:text="Button"
  android:layout_toRightOf="@id/btn2"/>

</RelativeLayout>

結語

  • 本文主要講解 Android:weight,margin,padding詳解實例
  • 下麵我將繼續對其他知識 深入講解 ,有興趣可以繼續關註
  • 小禮物走一走 or 點贊

送❤


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • springboot作為現在十分流行的框架,簡化Spring應用的初始搭建以及開發過程,現在我們就使用springboot來進行簡單的web項目搭建並對項目sql進行監控。 項目的搭建就省略了,springboot項目搭建好以後,進行一下操作, 本例子的項目使用 maven 管理的jar 1.加入依 ...
  • 引發思考 今天,發現開發項目中的單號重覆了。 這是多用戶併發操作相同數據導致的結果。有點抽象,理解如下:實際就是多個事務交叉執行(增、刪、查、改)了相同數據。導致一個事務不具有完整性了,資料庫的數據也不一致了(這裡‘’一致‘’可以理解為:我希望的數據,跟我想像的不一樣,比如明明我剛update某表性 ...
  • 定義 函數用於計算和返回一個結果值,把經常需要進行的計算寫成函數,函數的調用是表達式的一部分。 函數與過程在創建的形式上有些相似,也是編譯後放在記憶體中供用戶使用。 函數必須有一個返回值,而過程沒有做強制的規定。 RETURN在聲明部分需要定義一個返回參數的類型,而在函數體中必須有一個RETURN語句 ...
  • 事務 MULTI 、 EXEC 、 DISCARD 和 WATCH 是 Redis 事務相關的命令。事務可以一次執行多個命令, 並且帶有以下兩個重要的保證: 事務是一個單獨的隔離操作:事務中的所有命令都會序列化、按順序地執行。事務在執行的過程中,不會被其他客戶端發送來的命令請求所打斷。 事務是一個原 ...
  • Hadoop發展到今天家族產品已經非常豐富,能夠滿足不同場景的大數據處理需求。作為目前主流的大數據處理技術,市場上很多公司的大數據業務都是基於Hadoop開展,而且對很多場景已經具有非常成熟的解決方案。 作為開發人員掌握Hadoop及其生態內框架的開發技術,就是進入大數據領域的必經之路。 下麵詳細介 ...
  • 總結一下近期學習的大數據知識, 學習之前沒搞清楚的知識 傳統的web應用(LAMP、JavaEE、NODE系等)與大數據什麼關係? 之前一直以為大數據的東西就是來取代傳統的Web應用的,其實並不是這樣;即使是大數據的架構,應用層依然會是傳統的web應用,但是會根據數據特點對數據存儲(結構化數據依然會 ...
  • 註:此文章所寫內容完全在虛擬機配置,系統:centos,jdk和hadoop已經安裝完成所配集群包括hadoop01,hadoop02,hadoop03,hadoop04四台,ip分別為:192.168.80.101,192.168.80.102,192.168.80.103,192.168.80. ...
  • redis五大數據類型:string(字元串),hash(哈希,類似java的Map),list(列表),set(集合),zset(有序集合) 1、redis的鍵(key) keys 查詢資料庫中的key值,keys * 查出所有,keys rt* 查出匹配的key exists key 判斷key ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...