Android 開発 - パレットを理解する

  Android開発では、Googleのエンジニアがたくさんのボタンをパッケージ化してくれるので、開発がとても便利で便利です。

  さて、今日はよく使われるボタンについて学びましょう。Button ボタンについては、前のコースですでに詳しく説明したので、ここでは繰り返しません。

  Android 開発モニター ボタンのクリック イベント: http://www.cnblogs.com/xiao-chuan/p/6074075.html

 

1. 共通ボタン

  1. ボタンのパブリックプロパティ

  ボタンのパブリック属性には次のものが含まれます。1) よく使用されるスタイル属性

              a、背景

              b、マージン

              う、……

            2) 幅と高さ

              a、幅

              b、高さ

            3) サイズ

              a、サイズ

              b、最大(最小)

              う、……

            4) テキスト表示内容

              文章

              b、ヒント

            5) 固有のキーID

              援助

            6) クリックイベント

 

  2、テキストビュー:

    TextView: テキストボックス

    autoLink: テキストのデフォルトのパス

 

コードをコピーする
<TextView 
        android:layout_width="match_parent" 
        android:layout_height="50sp" 
        android:text="中国移動:10086" 
        android:textSize="20sp" 
        android:autoLink="phone" 
        /> 
    <TextView 
        android:layout_width="match_parent " 
        android:layout_height="50sp" 
        android:text="站长邮箱:[email protected]" 
        android:textSize="20sp" 
        android:autoLink="email" 
        /> 
    <TextView 
        android:layout_width="match_parent" 
        android:layout_height="50sp" 
        android:text="何か必要な場合は、Baidu を検索してください: http://www.baidu.com" 
        android:textSize="20sp" 
        android:autoLink="web" 
        />
コードをコピーする

 

ここで、最初の TextView をクリックすると、デフォルトの効果は電話になります。次に、2 番目と 3 番目の効果はどうなるでしょうか ~~ これが実現の効果図です。テキストの色を指定していないことがわかります。 , ここで注目なのがautoLinkにはデフォルトの色があります!

 

 

 

  3、テキストの編集

    編集テキスト入力ボックス

    inputType: 入力ボックスのテキスト形式

 

コードをコピーする
<EditText 
        android:id="@+id/userName" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="请输入用户名" 
        android:textColor="@android:color/holo_red_light" 
        android :textSize="20sp" 
        android:inputType="text" 
        android:maxLength="12" 
        /> 

    <EditText 
        android:id="@+id/userAge" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android :hint="请输入年龄"
        アンドロイド:maxLength="3" 
        android:numeric="integer" 
        android:inputType="number" 
        />
    <EditText 
        android:id="@+id/userPwd" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="请输入密码" 
        android:maxLength="12" 
        android:password="true" 
        android:inputType="textPassword" 
        /> 
    <EditText 
        android:id="@+id/userAddress" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="请输入详细地址" 
        android:maxLength= "500"
        アンドロイド:lines="3"
        アンドロイド:inputType="textMultiLine" 
        />
コードをコピーする

 

  入力方式:

    テキスト: テキスト形式

    textPassword: パスワード形式

    数値: 数値形式

    textMultiLink: アドレスバー形式

    ……

  ※入力時に入力方法が自動的に切り替わり、パスワード形式で入力した場合は入力内容が表示されません。

  

  4、バー

  ここでは次のように分けられます。

    1) SeekBar: 音量、明るさなどのスケジュール設定。

    2) RatingBar: 選択します。最も一般的なものは、電子商取引 Web サイトなどのコメントです。

    3) ProgressBar: 読み込み、ダウンロード、画像の読み込み、ファイルのダウンロードなど。

 

コードをコピーする
<TextView 
        android:id="@+id/showText" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="我是一个TextView" 
        android:textSize="20sp" 
        /> 
    <SeekBar 
        android: id="@+id/seekBar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:max="50" 
        android:progress="20" 
        /> 
    <RatingBar 
        android:id="@+id/評価バー」
        アンドロイド:layout_width="ラップコンテンツ" 
        android:layout_height="ラップコンテンツ" 
        android:numStars="5"
        アンドロイド:評価 = "1"
        android:stepSize="1" 
        /> 
    <ProgressBar 
        android:id="@+id/progressBar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:max="100" 
        android:progress="10" 
        /> 
    <ProgressBar 
        android:id="@+id/progressBar2" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:max="100" 
        android:progress="10" 
        style="?android:attr/progressBarStyleLarge" 
        />  
    <ProgressBar
        android:id="@+id/progressBar3" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:max="100" 
        android:progress="10" 
        style="?android:attr/progressBarStylehorizo​​ntal" 
        /> 
    <LinearLayout android:layout_width="match_parent" 
        android:layout_height="wrap_content" android :orientation="horizo​​ntal"> 
        <ボタン
            android:layout_width="0dp" 
            android:layout_weight="1" 
            android:layout_height="wrap_content" 
            android:text="开始" 
            android:onClick="doStart" 
            /> 
        <ボタン 
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1" 
            android:text="结束" 
            android:onClick="doStop" 
            /> 
    </LinearLayout>
コードをコピーする

 

  ページ効果:

 

 

  以下は、それぞれの効果と違いをより明確にするためのものです。

 

コードをコピーする
プライベート SeekBar sb; 
    プライベート TextView showText; 
    プライベート評価バー rb; 
    プライベートプログレスバー pb3; 
    @Override 
    protected void onCreate(Bundle SavedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_seek_bars); 

        showText=(TextView)findViewById(R.id.showText); 
        sb=(SeekBar)findViewById(R.id.seekBar); 
        rb=(評価バー)findViewById(R.id.評価バー); 
        pb3=(ProgressBar)findViewById(R.id.progressBar3); 
        //seekBar のためのイベント
        b.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {  
            @Override
            public void onStopTrackingTouch(SeekBar SeekBar) { 
            } 
            @Override 
            public void onStartTrackingTouch(SeekBar SeekBar) { 
            } 
            @Override 
            public void onProgressChanged(SeekBar SeekBar, int progress, 
                    boolean fromUser) { 
                //改变showText文字体大小
                showText.setTextSize(progress); 
            } 
        }); 

        rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { 
            @Override 
            public void onRatingChanged(RatingBar ratingsBar, float ratings, 
                    boolean fromUser) { 
                Toast.makeText(SeekBarsActivity.this, "你选择了"+評価+"星", 3000).show(); 
            }
        }); 
    } 

    //ダウンロードを開始 [注: ProgressBar を除くすべての UI は UI メイン スレッドで操作する必要があります] 
    boolean isRun=true; 
    public void doStart(View view) throws Exception{ 
        isRun=true; 
        // 子スレッドを構築しますプログレスバーの変更を実行します
        new Thread(new Runnable() {     
            @Override 
            public void run() { 
                //時間のかかる操作はメインスレッドでは実行できません
                while(isRun){ 
                    if(pb3.getProgress()< 100) { 
                        pb3.setProgress(pb3.getProgress()+1); 
                        try {  
                            Thread.sleep(50);
                        } catch (InterruptedException e) { 
                            e.printStackTrace(); 
                        } 
                    }else{ 
                        isRun=false; 
                        //マルチスレッド UI 更新を実装する最も簡単な方法
                        runOnUiThread(new Runnable() { 
                            public void run() { 
                                Toast.makeText(SeekBarsActivity.this, "ダウンロード完了" ,3000).show(); 
                            } 
                        }); 
                    } 
                } 
            } 
        }).start(); 
    } 
    //ダウンロード終了
    public void doStop(View view){ 
        isRun=false; 
    }
コードをコピーする

 

注: 
  1) ProgressBar を除くすべての UI は UI メインスレッドで操作する必要があります。そうでない場合はエラーが報告されます。
  2) 時間のかかる操作はメインスレッドでは実行できません。そうしないとエラーが報告されます。
  
  3) Google のエンジニアは Android 4.0 以降のバージョンで上記 2 点をサポートしないようにしたため、低コストを維持したい人は苦労するでしょう。バージョン どうするか〜〜自分で考えてください、非常に単純な質問です!

 

 

   

  

  5. 画像および単一選択複数選択ボックス

    1) imageButton: 画像ボタン

    2) imageView: 画像ビュー

            ImageView と HTML5 の比較:

            imageView: よりスムーズに動作し、ネットワークなしでも使用できます。

            HTML5: 実行速度は十分に滑らかではなく、インターネットがないと役に立ちません...しかし利点は、ページがより美しく、データ送信がより便利であることです。

 

    3) RadioButton: ラジオ ボタン。各要素は相互に排他的で、性別など 1 つだけ選択できます。

    4) チェックボックス: 複数選択ボタン。趣味など複数選択できます。

    5) ToggleButton: スイッチなどの単一のプロンプト ボタン

コードをコピーする
<RadioGroup android:id="@+id/rgsex" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizo​​ntal"> 
        <RadioButton 
            android:id="@+id/sexOne" 
            android: layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="男" 
            android:checked="true" 
            /> 
        <RadioButton 
            android:id="@+id/sexTwo" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="女" 
            /> 
    </RadioGroup>
    <LinearLayout android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizo​​ntal"> 
        <CheckBox 
            android:id="@+id/cb1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content " 
            android:text="篮球" 
            /> 
        <CheckBox 
            android:id="@+id/cb2" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="フットボール" 
            /> 
        <CheckBox 
            android:id="@+id/cb3"
            android:layout_width="wrap_content"src="@drawable/image001" 
        android:scaleType="fitXY"
            android:layout_height="wrap_content" 
            android:text="羽毛球" 
            /> 
    </LinearLayout> 

    <ToggleButton 
        android:id="@+id/stateButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textOn ="开灯" 
        android:textOff="关灯" 
        android:checked="true" 
        /> 
    <ImageButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/image001"maxWidth="120dp"
        アンドロイド:maxHeight="60dp"
        アンドロイド:maxWidth="120dp"
        アンドロイド:adjustViewBounds="true"
        アンドロイド:onClick="getValues" 
        />
コードをコピーする

 

   効果は次のとおりです。

 

 

  ps: 適切な写真が見つからず、他の人に宣伝したくないし、お金もないので、写真はコード化されています...

  

 

   以下は、それらの効果と違いをより明確にするためのものです。

 

コードをコピーする
プライベート RadioGroup rg; 
    プライベートチェックボックス cb1、cb2、cb3;    
    @Override 
    protected void onCreate(Bundle SavedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_buttons); 

        cb1=(チェックボックス)findViewById(R.id.cb1); 
        cb2=(チェックボックス)findViewById(R.id.cb2); 
        cb3=(チェックボックス)findViewById(R.id.cb3); 
        rg=(RadioGroup)findViewById(R.id.rgsex); 
        //监听单选按钮组
        Eventrg.setOnCheckedChangeListener(new OnCheckedChangeListener() {     
            @Override  
            public void onCheckedChanged(RadioGroup group, int selectedId) {
                RadioButton rb=(RadioButton)findViewById(checkedId);
                Toast.makeText(ButtonsActivity.this, "選択しました:"+rb.getText().toString(), 3000).show(); } }); } //
        [
    ラジオ

    ボタン | チェックボックス] 
    public void getValues( View view){ 
        //ラジオボタン
        RadioButton rb=(RadioButton)findViewById(rg.getCheckedRadioButtonId()); 
        StringBuffer sb=new StringBuffer(); 
        sb.append("Gender:"+rb.getText() .toString()+ "\n"); 

        // チェックボックス
        sb.append("趣味:"); 
        if(cb1.isChecked()) 
            sb.append(cb1.getText().toString()+", "); 
        if(cb3.isChecked()) 
            b.append(cb3.getText().toString()+","); 
        if(cb2.isChecked())
            sb.append(cb2.getText().toString()+","); 
        Toast.makeText(this, sb.toString(), 5000).show(); 
    }
コードをコピーする

  

  PS: Google のエンジニアがパッケージ化してくれたので、直接使用できます。これらのボタンを実装するための低レベルのフレームワークを作成することもできます。Java を学習しているときに、これらのボタンの実装を既に作成したと思います。実際、Google エンジニアによってカプセル化された基礎となるコードもその方法で実装されています。言ってるだけで~誰がそんなにつまらないの?既製品なんていらないよ!でも、今後 Android フレームワーク開発をするなら…自分で書かないといけませんね〜 基礎知識が更新されたら…より高度な内容になりますははは…まだ準備ができていません!

 

2. まとめ

  1. 実際には、よく使われるものもあれば、あまり使われないものもたくさんありますが、とにかく、誰もが自習する習慣を身につけてほしいと願っています...特に会社では!

  2. Androidフレームワークの開発は単なるJavaの知識なのでAndroid開発とは関係ありませんが、Androidに対する高い理解も必要です!

  3. Android ページにネストできますが、HTML5 と Android パレットの違いを区別する必要があります。

  4. TextView と EditView の違いは実際には非常に大きいです...

  5. パレットは、データ送信など、対応するイベントやビジネス ロジックと一緒に使用して初めて意味を持ちます~~ 今後のコースで詳しく説明します。

 

おすすめ

転載: blog.csdn.net/qq_33505204/article/details/78451830