當前位置:首頁 » 安卓系統 » android圓形view

android圓形view

發布時間: 2024-06-24 23:55:56

① Android 如何判斷一個View重繪或載入完成

1、view重繪時回調(即監聽函數,當view重繪完成自動動用,需要向view的觀察者添加監聽器)。格式:

view.getViewTreeObserver().addOnDrawListener(new OnDrawListener() {

@Override

public void onDraw() {

// TODO Auto-generated method stub

}

});

2、view載入完成時回調(當view載入完成自動動用,需要向view的觀察者添加監聽器)。格式:

view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

// TODO Auto-generated method stub

}

});

(1)android圓形view擴展閱讀:

兩種方式刷新:

1、主線程可以直接調用Invalidate()方法刷新

2、子線程可以直接調用postInvalidate()方法刷新。

API的描述 : Invalidatethe whole view. If the view is visible, onDraw(Canvas) will be called at somepoint in the future. This must be called from a UI thread. To call from anon-UI thread, call postInvalidate().。

API的描述譯文:當Invalidate()被調用的時候,View的OnDraw()就會被調用,Invalidate()必須是在UI線程中被調用,如果在新線程中更新視圖的就調用postInvalidate()。

② Android-EditView文本編輯控制項詳解

EditView 是Android開發當中運用到最多的控制項之一,主要用戶界面上的輸入框。

View --> TextView --> EditView 。

1.設置提示文本:

2.設置hint提示文字顏色:

3.設置輸入文本後的文字顏色:

4.設置輸入文本後的字體大小:

5.設置輸入文本後的字體樣式,bold(加粗),italic(傾斜),normal(默認是正常字體)。

6.設置被選中字體的顏色.默認為 Theme 主題中的 「colorAccent」的顏色。

7.設置被游標的顏色.默認為 Theme 主題中的 「colorAccent」的顏色。

8.設置文本的水平縮放系數。

9.設置hint提示文本的字體.normal(默認)\monospace\sans\serif。

10.設置EditText背景."@null"設置背景為透明.當我們設置背景後,EditText的下劃線就會消失。

11.設置文本的顏色,字體,大小和樣式。

12.設置只接收指定的文本內容,適合只能輸出特定內容的需求。

13.設置文本的類型,用於幫助輸入法顯示合適的鍵盤類型。

14.設置EditText最多接受的文本的個數:

15.設置EditText顯示的行數,設置兩行就顯示兩行,即使第二行沒有數據。

16.設置行間距的倍數. 如設置成1.5倍。

17.設置右下角IME動作與編輯框相關的動作,如actionDone右下角將顯示一個「完成」,而不設置默認是一個回車符號.

③ android 如何讓自定VIEW的顯示超出view的定義大小

  1. 在onTouchEvent裡面能獲得當前點擊位置的坐標,根據位置的變化,以原點為基礎,通過scrollBy來設置view的顯示位置。

  2. 自定義Layout實現放入其中的組件可以動態改變位置和大小。

自定義CustomLayout.java

package com.wxq.layout;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
//import android.widget.AbsoluteLayout;

public class CustomLayout extends ViewGroup {

public CustomLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

public CustomLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}

public CustomLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub

}

}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

3.其中只有自己的布局,其他的View要自己手動添加。

主程序:

TextView mTextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LayoutInflater inflater = getLayoutInflater();
LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.main, null);

mTextView = new TextView(this);
mTextView.setText("wxq say hello!");
mTextView.setTextColor(Color.WHITE);
mTextView.setBackgroundColor(Color.RED);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(100, 100);

CustomLayout cLayout = (CustomLayout) linearLayout.findViewById(R.id.cLayout);
cLayout.setBackgroundColor(Color.BLUE);
cLayout.addView(mTextView,layoutParams);
mTextView.layout(20, 20, 150+20, 150+20);

Log.d("wxq", "mTextView = " +mTextView + ",and parent is:"+mTextView.getParent());
mTextView.post(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub

Log.d("wxq", "textW = "+mTextView.getMeasuredWidth()+ ",H = "+mTextView.getMeasuredHeight());
}
});

setContentView(linearLayout);
}

實現的效果如下:

④ android glide 怎麼設置只有一個圓角

附錄1簡單介紹了android開源的圖片載入框架。在實際的開發中,雖然Glide解決了快速載入圖片的問題,但還有一個問題懸而未決:比如用戶的頭像,往往用戶的頭像是從伺服器端讀出的一個普通矩形圖片,但是現在的設計一般要求在APP端的用戶頭像顯示成圓形頭像,那麼此時雖然Glide可以載入,但載入出來的是一個矩形,如果要Glide在載入過程中就把矩形圖轉換成圓形的,則需要在Glide之上引入一個開源項目:glide-transformations
glide-transformations在github上的項目主頁是:https://github.com/wasabeef/glide-transformations
寫一個例子說明。

[java] view plain
package zhangphil.app;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class MainActivity extends AppCompatActivity {

//我csdn博客頭像
String url = "http://avatar.csdn.net/9/7/A/1_zhangphil.jpg";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//原圖,是我博客的頭像
ImageView image1 = (ImageView) findViewById(R.id.image1);
Glide.with(this).load(url).crossFade(1000).into(image1);

//原圖 -> 圓圖
ImageView image2 = (ImageView) findViewById(R.id.image2);
Glide.with(this).load(url).bitmapTransform(new CropCircleTransformation(this)).crossFade(1000).into(image2);

//原圖的毛玻璃、高斯模糊效果
ImageView image3 = (ImageView) findViewById(R.id.image3);
Glide.with(this).load(url).bitmapTransform(new BlurTransformation(this, 25)).crossFade(1000).into(image3);

//原圖基礎上復合變換成圓圖 +毛玻璃(高斯模糊)
ImageView image4 = (ImageView) findViewById(R.id.image4);
Glide.with(this).load(url).bitmapTransform(new BlurTransformation(this, 25), new CropCircleTransformation(this)).crossFade(1000).into(image4);

//原圖處理成圓角,如果是四周都是圓角則是RoundedCornersTransformation.CornerType.ALL
ImageView image5 = (ImageView) findViewById(R.id.image5);
Glide.with(this).load(url).bitmapTransform(new RoundedCornersTransformation(this, 30, 0, RoundedCornersTransformation.CornerType.BOTTOM)).crossFade(1000).into(image5);
}
}

布局則比較簡單,是一個垂直方向的線性布局布局了5個ImageView,不再贅述。

代碼運行結果。

附錄:

1,《Android圖片載入與緩存開源框架:Android Glide》鏈接:http://blog.csdn.net/zhangphil/article/details/45535693

⑤ android開發圖形類主要有哪些

  • Canvas類:

    Canvas類代表畫布,通過該類使用的方法,可以繪制各種圖形(如矩形、圓形、線形)通常情況下,在Android中繪制圖形需要先創建繼承自View的類的視圖,並且在該類中重寫其OnDraw(Canvas canvas)方法,然後在繪制的Activity中添加該視圖。

  • View:組件,理解為畫布

    Drawable:所有可見對象的描述,理解為:素材類;

    Bitmap:圖片類;

    Canvas:畫筆;

    Paint:畫筆樣式與顏色、特效的集合;

    對於Android UI開發自繪控制項和游戲製作而言掌握好繪圖基礎是必不可少的有關OpenGL ES相關。

熱點內容
怎麼滑動輸入密碼 發布:2024-09-29 02:31:45 瀏覽:231
pythonfinally 發布:2024-09-29 02:20:21 瀏覽:16
主播是什麼配置 發布:2024-09-29 01:40:21 瀏覽:199
晨曦軟體加密狗 發布:2024-09-29 01:40:18 瀏覽:308
浙江大學我的世界伺服器雲伺服器 發布:2024-09-29 01:40:14 瀏覽:64
怎麼存儲鮮姜 發布:2024-09-29 01:39:34 瀏覽:224
安卓手機如何降低白屏點 發布:2024-09-29 01:39:31 瀏覽:342
extjs4多文件上傳 發布:2024-09-29 01:34:32 瀏覽:898
安卓機按鍵怎麼隱藏 發布:2024-09-29 01:34:29 瀏覽:690
加密u盤軟體下載 發布:2024-09-29 01:15:26 瀏覽:88