當前位置:首頁 » 安卓系統 » android基本控制項

android基本控制項

發布時間: 2022-06-22 06:44:12

㈠ 關於Android編程中的控制項名稱

我沒有用過小米的系統,但從表現上來看很可能是
tabhost
也可以使用radiogroup來實現
還有pageview也可以。最主要看實現的人喜歡用
哪個控制項

㈡ 最新的Android控制項有哪些

1.MaterialStepperView
它是用Material Design實現Steppers的。

目前,Stepper只有垂直視圖,但將來會有更多的風格。你可以嘗試一下,如下圖:
你可以自定義normal/active兩個狀態的顏色,完成圖標,開啟動畫並設置動畫時長。可通過Github上的設置項和樣式查閱所有設置項。該庫支持API 17+,詳情請查閱wiki文檔。

2. MultiSnapRecyclerView
這是分屏滾動的Android庫。
MultiSnapRecyclerView為RecyclerView提供了分屏功能。

目前提供的功能有:
start, end和center三個位置的吸附,
snap count 指定要分屏的數量,
支持水平和垂直分屏,
滾動時的回調。
3. Garland View for Android
該庫可實現如下的布局:

GarlandView 外部是一個水平滾動的視圖,視圖內的每一個子視圖可垂直滾動。
你可以在README中找到其他重要信息。還有一個示例App。該庫支持API 19及更高版本。
4. VegaLayoutManager
這是一個自定義的布局管理器——滾動時縮小並淡出頭部。這是受到Dribble項目的啟發。

5. ExpandableLayout
這個庫的名字不言而喻,它是一個基於LinearLayout的可擴展的布局。
README里含有你啟動時需要的所有信息,另外,還有一個示例App可以幫助你快速跳轉到代碼中。
6. SwipeBackLayout
SwipeBackLayout允許你使用手勢返回上一個界面。
你可以設置滑動方向,如從左到右、從右到左、從頂部到底部、從底部到頂部。
你還可以設置是否只能從邊緣滑動。
SwipeBackLayout只能包含一個子布局,例如:
LinearLayout,RelativeLayout,FrameLayout,TableLayout等。
ScrollView,HorizontalScrollView,NestedScrollView等。
RecyclerView,AbsListView(ListView)等子類。
ViewPager,WebView等。
該項目裡面有一個詳細說明的文檔、示例APP和一個APK。

㈢ Android基礎技術及基本控制項

安卓基礎技術主要是講解一些安卓系統運行的原理,還有一些基本的組件,所有的安卓應用程序都是在這些組件構成的,基本控制項主要就是一些類似按鈕,進度條,滾動條這些圖形界面組件,還有一些是用戶自定義的組件。

㈣ 幾個Android控制項屬性筆記

第一類:屬性值為true或false
android:layout_centerHrizontal 水平居中 (Hrizontal表示水平)
android:layout_centerVertical 垂直居中 (Vertiacl表示垂直)
android:layout_centerInparent 相對於父元素完全居中
android:layout_alignParentBottom 貼緊父元素的下邊緣 (align 表示使什麼成為一行)
android:layout_alignParentLeft 貼緊父元素的左邊緣
android:layout_alignParentRight 貼緊父元素的右邊緣
android:layout_alignParentTop 貼緊父元素的上邊緣
android:layout_alignWithParentIfMissing 如果對應的兄弟元素找不到的話就以父元素做參照物
第二類:屬性值必須為id的引用名"@id/id-name"
android:layout_below 在某元素的下方
android:layout_above 在某元素的的上方
android:layout_toLeftOf 在某元素的左邊
android:layout_toRightOf 在某元素的右邊
android:layout_alignTop 本元素的上邊緣和某元素的的上邊緣對齊
android:layout_alignLeft 本元素的左邊緣和某元素的的左邊緣對齊
android:layout_alignBottom 本元素的下邊緣和某元素的的下邊緣對齊
android:layout_alignRight 本元素的右邊緣和某元素的的右邊緣對齊
第三類:屬性值為具體的像素值,如30dip,40px
android:layout_marginBottom 離某元素底邊緣的距離 margin英文是邊緣的意思
android:layout_marginLeft 離某元素左邊緣的距離
android:layout_marginRight 離某元素右邊緣的距離
android:layout_marginTop 離某元素上邊緣的距離

㈤ android界面開發常用的控制項有哪些

控制項開發大致分為兩種: 1.組合式開發。將幾個android現成的控制項,如ImageView,Button等糅合在一起。 2.單獨開發。一般繼承View,然後重寫其onDraw和onMeasure等方法。若是ViewGroup,則還需重寫measureChildren等。 上面說的是2D控制項。3D則需繼承SurfaceView。

㈥ android自定義控制項怎麼用

一、控制項自定義屬性介紹
以下示例中代碼均在values/attrs.xml 中定義,屬性均可隨意命名。
1. reference:參考某一資源ID。
示例:
<declare-styleable name = "名稱">

<attr name = "background" format = "reference" />
<attr name = "src" format = "reference" />
</declare-styleable>

2. color:顏色值。
示例:
<declare-styleable name = "名稱">

<attr name = "textColor" format = "color" />
</declare-styleable>

3. boolean:布爾值。
示例:
<declare-styleable name = "名稱">

<attr name = "focusable" format = "boolean" />
</declare-styleable>

4. dimension:尺寸值。
示例:
<declare-styleable name = "名稱">

<attr name = "layout_width" format = "dimension" />
</declare-styleable>

5. float:浮點值。
示例:
<declare-styleable name = "名稱">

<attr name = "fromAlpha" format = "float" />
<attr name = "toAlpha" format = "float" />
</declare-styleable>

6. integer:整型值。
示例:
<declare-styleable name = "名稱">

<attr name = "frameDuration" format="integer" />
<attr name = "framesCount" format="integer" />
</declare-styleable>

7. string:字元串。
示例:
<declare-styleable name = "名稱">

<attr name = "text" format = "string" />
</declare-styleable>

8. fraction:百分數。
示例:

<declare-styleable name="名稱">
<attr name = "pivotX" format = "fraction" />
<attr name = "pivotY" format = "fraction" />
</declare-styleable>

9. enum:枚舉值。
示例:
<declare-styleable name="名稱">

<attr name="orientation">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
</declare-styleable>

10. flag:位或運算。
示例:
<declare-styleable name="名稱">

<attr name="windowSoftInputMode">
<flag name = "stateUnspecified" value = "0" />
<flag name = "stateUnchanged" value = "1" />
<flag name = "stateHidden" value = "2" />
<flag name = "stateAlwaysHidden" value = "3" />
</attr>
</declare-styleable>

11.多類型。
示例:

<declare-styleable name = "名稱">
<attr name = "background" format = "reference|color" />
</declare-styleable>

二、屬性的使用以及自定義控制項的實現
1、構思控制項的組成元素,思考所需自定義的屬性。
比如:我要做一個 <帶陰影的按鈕,按鈕正下方有文字說明>(類似9宮格按鈕)
新建values/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="custom_view">
<attr name="custom_id" format="integer" />
<attr name="src" format="reference" />
<attr name="background" format="reference" />
<attr name="text" format="string" />
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
</declare-styleable>
</resources>

以上,所定義為custom_view,custom_id為按鈕id,src為按鈕,background為陰影背景,text為按鈕說明,textColor為字體顏色,textSize為字體大小。

2、怎麼自定義控制項呢,怎麼使用這些屬性呢?話不多說請看代碼,CustomView :

package com.nanlus.custom;
import com.nanlus.custom.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomView extends FrameLayout implements OnClickListener {
private CustomListener customListener = null;
private Drawable mSrc = null, mBackground = null;
private String mText = "";
private int mTextColor = 0;
private float mTextSize = 20;
private int mCustomId = 0;
private ImageView mBackgroundView = null;
private ImageButton mButtonView = null;
private TextView mTextView = null;
private LayoutParams mParams = null;
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.custom_view);
mSrc = a.getDrawable(R.styleable.custom_view_src);
mBackground = a.getDrawable(R.styleable.custom_view_background);
mText = a.getString(R.styleable.custom_view_text);
mTextColor = a.getColor(R.styleable.custom_view_textColor,
Color.WHITE);
mTextSize = a.getDimension(R.styleable.custom_view_textSize, 20);
mCustomId = a.getInt(R.styleable.custom_view_custom_id, 0);
mTextView = new TextView(context);
mTextView.setTextSize(mTextSize);
mTextView.setTextColor(mTextColor);
mTextView.setText(mText);
mTextView.setGravity(Gravity.CENTER);
mTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mButtonView = new ImageButton(context);
mButtonView.setImageDrawable(mSrc);
mButtonView.setBackgroundDrawable(null);
mButtonView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mButtonView.setOnClickListener(this);
mBackgroundView = new ImageView(context);
mBackgroundView.setImageDrawable(mBackground);
mBackgroundView.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addView(mBackgroundView);
addView(mButtonView);
addView(mTextView);
this.setOnClickListener(this);
a.recycle();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mParams = (LayoutParams) mButtonView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
mButtonView.setLayoutParams(mParams);
}
mParams = (LayoutParams) mBackgroundView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
mBackgroundView.setLayoutParams(mParams);
}
mParams = (LayoutParams) mTextView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
mTextView.setLayoutParams(mParams);
}
}
public void setCustomListener(CustomListener l) {
customListener = l;
}
@Override
public void onClick(View v) {
if (customListener != null) {
customListener.onCuscomClick(v, mCustomId);
}
}
public interface CustomListener {
void onCuscomClick(View v, int custom_id);
}
}
代碼很簡單,就不多說,下面來看看我們的CustomView是怎麼用的,請看:

3、自定義控制項的使用
話不多說,請看代碼,main.xml:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:nanlus="http://schemas.android.com/apk/res/com.nanlus.custom"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<com.nanlus.custom.CustomView
android:id="@+id/custom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
nanlus:background="@drawable/background"
nanlus:custom_id="1"
nanlus:src="@drawable/style_button"
nanlus:text="按鈕1" >
</com.nanlus.custom.CustomView>
</LinearLayout>
</RelativeLayout>

在這里需要解釋一下,
xmlns:nanlus="http://schemas.android.com/apk/res/com.nanlus.custom"
nanlus為在xml中的前綴,com.nanlus.custom為包名

4、在Activity中,直接上代碼
package com.nanlus.custom;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.nanlus.BaseActivity;
import com.nanlus.custom.R;
import com.nanlus.custom.CustomView.CustomListener;
public class CustomActivity extends BaseActivity implements CustomListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((CustomView) this.findViewById(R.id.custom1)).setCustomListener(this);
}
@Override
public void onCuscomClick(View v, int custom_id) {
switch (custom_id) {
case 1:
Toast.makeText(this, "hello !!!", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}

㈦ 如何系統的學習android自定義各種酷炫控制項

首先,為什麼需要自定義View?

1. 現有的View滿足不了你的需求,也沒有辦法從已有控制項派生一個出來;界面元素需要自己繪制。
2. 現有View可以滿足要求,把它做成自定義View只是為了抽象:為這個自定義View提供若干方法,方便調用著操縱View。通常做法是派生一個已有View,或者結合xml文件直接inflate。

目前常用的基本上是第二種方式,這種方式非常簡單,與通常的View使用方法基本相同,但是作用卻異常強大,擁有了這一層抽象,代碼更加整潔也更容易維護,通過抽取自定義View的公共操作方法也減少了冗餘代碼,雖然簡單,但不可忽視。

大多數人感覺神秘的應該是第一種,自繪控制項,完全自定義;但其實這兩種方式歸根結底全部都是自繪;不信你去看看TextView的源碼。只不過通常情況下系統幫我們繪制好了一些控制項給開發者使用;OK,接下來就是一個問題。

在講述之前我還是啰嗦地重申一下,復用已有View是最最常用也最有效的自定義View方式,必須熟練使用。

其次,如何自定義View?

想一下,一個View給用戶最直觀的感知是什麼?靜止的形態和動態的操作。靜止的形態意思就是一個View呈現到用戶眼裡長成啥樣子?動態操作指的是,用戶與View之間可以有哪些交互?點擊滑動View的不同地方會有什麼反應?

1. 靜態

如果一個自定義View的樣式都沒有辦法繪制出來,那麼後續的交互就是空談了;我們一步步分解這個問題。

1.1 你的自定義View分為哪幾個部分?是所有的部分都需要手動繪制還是只有一部分——找出需要完全自定義的部分,其他的部分用已有View實現。

1.2 你的自定義View的每個部分長成什麼樣,佔用多大空間——結合理論知識View的measure過程,比如match_parent, wrap_content結合父View的laout_params參數最終測量大小是多少?

1.3 你的自定義View每個部分擺放在哪?相對位置如何?——View的layout過程。

1.4 你的自定義View那些完全需要手動繪制的部分是什麼樣,如何繪制?

你得學會操縱Canvas,學會2D繪圖,什麼?你跟我說3D,OpenGL?學會這些再說。

㈧ android列表常用控制項有哪些

一、概述 Android中的有個原生的下拉列表控制項Spinner,但是這個控制項有時候不符合我們自己的要求, 比如有時候我們需要類似windows 或者web網頁中常見的那種下拉列表控制項,類似下圖這樣的: 這個時候只有自己動手寫一個了。其實實現起來不算很難, 本文實現的方案是採用TextView +ImageView+PopupWindow的組合方案。 先來看看我們的自己寫的控制項效果圖吧:(源碼在文章下面最後給出哈!) 二、自定義下拉列表框控制項的實現 1. 自定義控制項用到的布局文件和資源: 結果框的布局頁面:dropdownlist_view.xml: <?xml version="1.0" encoding="utf-8"?>

㈨ android這么多ui控制項怎樣才能記牢呢

布局(Layout)的概念是針對Activity的,Activity就是布滿整 個Android設備的窗口或者懸浮於其他窗口上的交互界面。在一個應用程序中通常由多個Activity構成,每個需要顯示的Activity都需要在AndroidManifest.xml文件之中聲明。

通常情況下,開發人員可以使用兩種方式來創建UI組件,一種方式是使用XML方式來配置UI組件的相關屬性,然後裝載這些UI組件,這也是最常用的方式。但是有些特殊情況下,需要動態生成UI組件,則需要使用第二種方式,完全使用java代碼來創建UI組件。

XML布局文件是Android系統中定義的Layout的常用方式,所有布局文件必須包含在res/layout目錄中,且必須符合Java的命名 規范。當在res/layout目錄下新增了布局文件之後,R.java文件會自動收錄該布局資源,Java代碼可通過setContentView方法 在Activity中顯示該Layout。

setContentView(R.layout.<資源名稱>);

在布局文件中可以指定UI組件的android:id屬性,該屬性的屬性值代表該組件的唯一標識。通過Activity.findViewById()訪問,並且findViewById()必須在setContentView載入xml文件之後使用,否則會拋出異常。

findViewById(R.id.)

Android應用的絕大部分UI組件都放在android.widget包及其子包、android.view包及其子包中,Android應用的 所有UI組件都繼承了View類。View類還有一個重要的子類:ViewGroup,ViewGroup類是所有布局管理器的父類。

ViewGroup容器控制其子組件的分布依賴於ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams兩個內部類。

ViewGroup.LayoutParams提供兩個XML屬性設定組件的大小。

android:layout_height:指定該子組件的基本高度;

android:layout_width:指定該子組件的基本寬度。

這兩個屬性有三個基本值,這兩個屬性有三個特定的值:

fill_parent:指定組件的高度、寬度與父容器組件的一樣。

match_parent:與fill_parent一樣,Android2.2開始推薦使用。

warp_content:內容包裹。

ViewGroup.MarginLayoutParams用於控制子組件周圍的頁邊距。

android:layout_marginBottom(下邊距);

android:layout_marginLeft(左邊距);

android:layout_marginRight(右邊距):

layout_marginTop(上邊距)

對於View的尺寸,android提供了三種單位供選擇使用:

px:像素。

dp:dpi,表示屏幕實際的像素。

sp:與scale無關的像素,與dp類似。

尺寸單位選擇的技巧:如果設置長度、高度等屬性時可以使用dp或sp,但是如果設置字體,需要使用px。如果使用dp或sp,系統會根據屏幕密度的變化進行轉換。

為了適應各種界面風格,Android提供了五種布局規范,利用這五種布局,基本上可以在設備上隨心所欲的擺放任何UI組件,這五種布局分別是:

FrameLayout(幀布局)。

LinearLayout(線性布局)

RelativeLayout(相對布局)。

TableLayout(表格布局)。

AbsoluteLayout(絕對布局)。

線性布局(LinearLayout)

LinearLayout是最常用的布局方式,在XML文件中使用標記。它會將容器里的UI組件一個一個挨著排列起來。但是LinearLayout不會換行,當UI組件超出屏幕之後,則不會被顯示出來。LinearLayout有兩個重要的XML屬性:androidgravity(對齊方 式);android:orientation(排列方式)。

android:orientation(排列方式),設定了LinearLayout中包含的UI組件的排列方式,有兩個選項vertical(豎向)、horizontal(橫向,默認值)

android:gravity(對齊方式),設定LinearLayout中包含UI組件的對齊方式,其選項很多,常用上(top)、下(bottom)、左(left)、右(right)。

熱點內容
一汽桌面雲伺服器地址 發布:2024-05-06 21:19:23 瀏覽:994
北京市社保官網登錄密碼是什麼 發布:2024-05-06 21:19:15 瀏覽:379
c語言數組的刪除 發布:2024-05-06 20:52:33 瀏覽:397
機械戰警用什麼配置好看 發布:2024-05-06 20:27:12 瀏覽:435
win10添加python環境變數 發布:2024-05-06 20:27:12 瀏覽:313
並聯臂演算法 發布:2024-05-06 20:02:11 瀏覽:623
cf跟dnf哪個需求配置高 發布:2024-05-06 20:01:23 瀏覽:657
什麼配置皮筋能打老鼠嗎 發布:2024-05-06 19:54:32 瀏覽:742
壓縮機油壓差報警 發布:2024-05-06 19:45:08 瀏覽:336
打游戲腳本好不好 發布:2024-05-06 19:44:00 瀏覽:235