首先將網上搜集到的圖片保存在桌面,并復制該圖片,

成功復制該圖片后,進入AndroidStudio中,找到res檔案夾下的drawable檔案夾,將先前復制的圖片粘貼到該檔案夾下,

而后便會出現“選擇目標目錄”,一般來說我們直接選擇粘貼到drawable檔案夾就好了,

接下來給圖片改個名,最好將圖片的名字改成a~z的小寫字母或組合(大寫不行),或者1~9的數字或組合,

那么就粘貼完成了,

而后將視線移到右側,點擊下圖中右上角的Design按鈕,進入設計界面,

而后點擊左側Palette欄中的Common欄,再點擊imageView按鈕,將其直接拖動到下方的Component Tree欄中,

隨后便會出現“Pick a Resources”視窗,從中選擇我們先前粘貼到res檔案夾中的圖片,

選擇后點擊確定,右側的UI設計界面中便會出現我們所需的圖片,

成功放置圖片后,一般來說我們并不能直接控制圖片在UI中的大小 位置之類的資料(直接控制指的是在上圖中拖動圖片放縮之類的,這是不行的),我們只能在activity main.xml中進行編程,來控制圖片的大小以及位置(通過編程可以進行其他更多設定),如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<Button
android:id="@+id/btn_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按鈕1"/>
<Button
android:id="@+id/btn_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click"
android:text="按鈕2" />
<Button
android:id="@+id/btn_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按鈕3" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/d" />
</LinearLayout>
——僅供個人學習筆記之用
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/302533.html
標籤:其他
上一篇:Android編程權威指南第3版 2.7 挑戰練習:為 TextView 添加監聽器
下一篇:安卓開發基礎
