Android常用コントロール
7477 ワード
1.テキストコントロールTextView
ランニングライト効果:システムが提供するtextViewテキストにはランニングライト効果が付いていますが、フォーカスが得られたときにしか効果が得られません.
TextViewクラスのisFocused()メソッドを書き換えることで、常にtrueを返す必要があります.
2.EditView編集ボックス
Activityを開いたばかりの頃は、レイアウトにEditViewコントロールが含まれているために自動的に入力メソッドがポップアップされる可能性があります.この嫌な入力ボックスを削除するには、EditViewの親レイアウトに属性を追加すればいいのです
UIレイアウトも入力方式から分離され、EditText領域は自動的に縮小された.これにより,ユーザ入力に影響を及ぼさず,ユーザのさらなる操作にも影響を及ぼさない.
また,入力方式を開いてもユーザはUIの全貌を見ることができ,比較的快適で友好的である.
この時点でAndroidManifest.xmlファイルというactivityにこの属性を入れればいいです
ログイン名がemailタイプの場合、android:inputTypeプロパティを設定すると、ポップアップ入力方式を入力メールフォーマットに直接適応させることができます.
3.ViewPageこのコントロールを使用するには、まずこのパッケージを追加する必要があります.プロジェクト-->右クリックandroid tools-->addSupportLibrary jarパッケージを追加します.
最初のステップxmlにコントロールを追加する
ステップ2でPagerAdapterを継承した後、ViewPagerがこのAdapterを追加すればよい
4.プロンプトボックスDialog
すべてのプロンプトクラス懸濁ボックスは、このクラスDialogから継承されます.最も一般的な2つのプロンプトボックスの1つはAlertDialogで、もう1つはProgresDialogで、前者はユーザーとインタラクティブにユーザーの操作を受け入れることができて、後者はユーザーに時間のかかる操作が進行していることを提示して、ユーザーは辛抱強く待ってください
自分のアプリケーションがシステムのトピックと一致するのは難しいので、通常はこの2つのプロンプトボックスを自分で書きます.カスタムProgresDialogの例を次に示します
pd_viewのコード
Activityは、すべてのプロンプトボックスを専門に管理する方法を提供します.
前者はプロンプトボックスを消去し、後者は反応せず、自分でonKeyDown()メソッドを書き換えてプロンプトボックスを消去する必要があります
5 ContextMenuコンテキストメニュー
第1ステップactivity onCreateContextMenu()メソッドの上書き
第2歩はコンテキストメニューに1つのVIewを登録して、長い押しの時メニューを弾き出します
registerForContextMenu(View);
ランニングライト効果:システムが提供するtextViewテキストにはランニングライト効果が付いていますが、フォーカスが得られたときにしか効果が得られません.
TextViewクラスのisFocused()メソッドを書き換えることで、常にtrueを返す必要があります.
public class ScrollForeverTextView extends TextView {
public ScrollForeverTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public ScrollForeverTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollForeverTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;//
}
}
xmlに組み込まれたコードScrollForeverTextViewの前にあるのは、このクラスが存在するパッケージ名です. <com.quickeasytrip.view.ScrollForeverTextView
android:id="@+id/book_hotel_name_verify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
/>
2.EditView編集ボックス
Activityを開いたばかりの頃は、レイアウトにEditViewコントロールが含まれているために自動的に入力メソッドがポップアップされる可能性があります.この嫌な入力ボックスを削除するには、EditViewの親レイアウトに属性を追加すればいいのです
: EditText ,
android:focusable="true"
android:focusableInTouchMode="true"
, EditText !
点編集ボックスユーザー名パスワードを入力するとき、最もよくある問題は、入力方式が編集ボックスを遮断し、次のEditViewを編集するには入力方式を閉じなければならないということです.UIレイアウトも入力方式から分離され、EditText領域は自動的に縮小された.これにより,ユーザ入力に影響を及ぼさず,ユーザのさらなる操作にも影響を及ぼさない.
また,入力方式を開いてもユーザはUIの全貌を見ることができ,比較的快適で友好的である.
この時点でAndroidManifest.xmlファイルというactivityにこの属性を入れればいいです
android:windowSoftInputMode="adjustResize"
ログイン名がemailタイプの場合、android:inputTypeプロパティを設定すると、ポップアップ入力方式を入力メールフォーマットに直接適応させることができます.
android:inputType="textEmailAddress"
android:inputType="number"
3.ViewPageこのコントロールを使用するには、まずこのパッケージを追加する必要があります.プロジェクト-->右クリックandroid tools-->addSupportLibrary jarパッケージを追加します.
最初のステップxmlにコントロールを追加する
<android.support.v4.view.ViewPager
android:id="@+id/pagerMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/advert" />
ステップ2でPagerAdapterを継承した後、ViewPagerがこのAdapterを追加すればよい
public class MyPagerAdapter extends PagerAdapter {
public List<View> mListViews = null;
ViewPager mViewPager = null;
public MyPagerAdapter(List<View> mListViews, ViewPager viewPager) {
this.mViewPager = viewPager;
this.mListViews = mListViews;
}
@Override
public int getCount() {
return mListViews.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == (arg1);
}
@Override
public Object instantiateItem(View container, int position) {
((ViewPager) container).addView(mListViews.get(position));
return mListViews.get(position);
}
@Override
public void destroyItem(View container, int position, Object object) {
if (mListViews.size() > 0) {
if ((mListViews.size() - 1) >= position) {
mViewPager.removeView(mListViews.get(position));
}// , ,
}
}
}
4.プロンプトボックスDialog
すべてのプロンプトクラス懸濁ボックスは、このクラスDialogから継承されます.最も一般的な2つのプロンプトボックスの1つはAlertDialogで、もう1つはProgresDialogで、前者はユーザーとインタラクティブにユーザーの操作を受け入れることができて、後者はユーザーに時間のかかる操作が進行していることを提示して、ユーザーは辛抱強く待ってください
自分のアプリケーションがシステムのトピックと一致するのは難しいので、通常はこの2つのプロンプトボックスを自分で書きます.カスタムProgresDialogの例を次に示します
View pdView = factory.inflate(R.layout.pd_view, null);
Dialog mProgressDialog = new Dialog(this, R.style.nobgDialog);
mProgressDialog.setContentView(pdView); // show mProgressDialog.show();
pd_viewのコード
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:background="@drawable/pd_bg"
android:gravity="center"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/loading_process"
android:layout_width="34dip"
android:layout_height="34dip"
android:indeterminate="false"
android:indeterminateDrawable="@anim/frame_animation" />
<TextView
android:id="@+id/mPdText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:text=" ..."
android:textColor="@android:color/black"
android:textSize="14dip"
android:textStyle="bold" />
</LinearLayout>
アニメーションリストコードは、フレームごとに8フレーム100ミリ秒に達したときに最もスムーズに回転します.<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item android:drawable="@drawable/scan_01" android:duration="100"/>
<item android:drawable="@drawable/scan_02" android:duration="100" />
<item android:drawable="@drawable/scan_03" android:duration="100" />
<item android:drawable="@drawable/scan_04" android:duration="100" />
<item android:drawable="@drawable/scan_05" android:duration="100" />
<item android:drawable="@drawable/scan_06" android:duration="100" />
<item android:drawable="@drawable/scan_07" android:duration="100" />
<item android:drawable="@drawable/scan_08" android:duration="100" />
</animation-list>
Activityは、すべてのプロンプトボックスを専門に管理する方法を提供します.
@Override
protected Dialog onCreateDialog(int id, Bundle args) {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage(" ");
return dialog;
}
showDialog(id)を呼び出す.具体的なヒントボックスを表示し、プログラミング時にdialogを表示する.show()も表示され、この方法は役に立たないようですが、実際にはbackキーを押して操作を返すと前者はプロンプトボックスを消去し、後者は反応せず、自分でonKeyDown()メソッドを書き換えてプロンプトボックスを消去する必要があります
5 ContextMenuコンテキストメニュー
第1ステップactivity onCreateContextMenu()メソッドの上書き
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// set context menu title
menu.setHeaderTitle(" ");
// add context menu item
menu.add(0, 1, Menu.NONE, " ");
menu.add(0, 2, Menu.NONE, " ");
menu.add(0, 3, Menu.NONE, " ");
menu.add(0, 4, Menu.NONE, " ");
super.onCreateContextMenu(menu, v, menuInfo);
}
第2歩はコンテキストメニューに1つのVIewを登録して、長い押しの時メニューを弾き出します
registerForContextMenu(View);