まず、基本的なコントロール
建物であり、当社の使用のための多くのAndroidのインターフェイスコントロールは、あるTextViewの、のEditText、ボタンを持って、ImageViewのというように、それはこれらのコントロールであり、私たちは素敵なインターフェイスのフレームワークを構築することができ、この章のショーでは、基本的なコントロールのプロパティを説明し、いくつかのAndroidとは、一般的に、プロジェクトで使用されるコントロールが付属しています。
すべてのコントロールは、属性を持っている必要があります。長さと幅のコントロールを設定します
アンドロイド:layout_width
アンドロイド:layout_height
1.TextView
これは、いくつかのテキスト情報を表示するには、主に、テキストコントロールです。
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="25sp"
android:textColor="#ff0000"
android:text="这是helloworld"
android:textStyle="blod"
/>
1.android:idのTextViewプロパティは、IDによって一意識別子のTextView、我々はfindViewByIdによる制御を得ることができるJavaコード()メソッドのIDを表します。上記ウィジェットの一意のIDは、TextViewにあります。
2.android:layout_widthプロパティは、コントロールの幅を表し、この属性の値は、親ビューの制御と同じ幅を示し、match_parentあります。
3.android:layout_heightプロパティは、コントロールの高さを表し、プロパティの値がwrap_contentで、コンテンツの高さに応じて、制御変更の高さを表しています。
4.android:gravityプロパティは、TextViewのテキストの配置を表し、さまざまな方法がありますが、今回の選挙では、我々は、中心、中央にあります。
5.android:textSizeプロパティは、テキストの大きさのTextViewモデル内のテキストを表します。
6.android:textColorプロパティは、属性値が16進数のカラー値である、のTextViewのテキストの色です。
7.android:textのTextViewプロパティが表示された値を設定するために使用されています。
8 androidtextStyleフォントスタイル:BLOD(太字)、イタリック(斜体)、ノーマル(ルーチン)
もちろん、TextViewには、あなたは自分の時間に学習に放課後の関心を必要とし、ここで提示されていない他の多くの属性があり、探索します。
2.EditText
EditTextはコントロールとユーザーとの対話のための重要なプログラムであり、これは、ユーザーが入力したコンテンツコントロールを編集することができます。同様に、構成することができるとのTextView特性が類似している、いくつかの他の共通の属性があります。
●アンドロイド:この属性は、示唆に富むテキストの期間を指定するヒント、ユーザが任意のコンテンツを入力したときに、このテキストは自動的に消えます。
●アンドロイド:最大行数を指定しますMAXLINEのEditText、入力の内容が上にスクロールされるテキストの最大行数を超えた、とのEditTextストレッチを継続していないときにそう。
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入内容"
android:maxLines="2"
/>
3.Button
ボタンは、ユーザーがクリックしたボタンですAndroidの開発では、ボタンは、最も一般的に使用されるコントロールの一つです。
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是button"
android:textAllCaps="false"
/>
キャンセルする場合はfalseにtextAllCapsプロパティ:すべての文字が自動的に大文字ボタンを変換します、我々はアンドロイドが必要
▲
私たちは、その後、応答しませんでしたそれをクリックし、インターフェイスにボタンを追加しましたので、私たちは、ボタンのリスナーを登録し、その中にクリック・ロジックを記述する必要があります。
public class MainActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"你点击了button",Toast.LENGTH_SHORT).show();
}
});
}
使用、ボタンの結合があるまず、ボタンオブジェクトの作成]ボタンをクリックし、その後、我々は(イベントが実行するために作成されたとき、彼らはこの方法で記述されたコントロールや他のものを初期化する必要が返されます)のonCreateメソッドに必要findViewById()が発見され、名前がレイアウトファイルのボタンのidです。ボタンは、onClickの内の対応するロジックを記述し、書き換え、setOnClickListenerを呼び出します。ここではトーストとテキストの表示があります。
4.ImageView
これは、私たちのプログラムは、よりカラフルにすることができ、表示制御、の写真です。このスペースを学習、事前にいくつかの写真を準備するためにお金が必要、写真は通常描画可能resディレクトリに私たち自身の場所が必要です。ここで私は、内部の描画可能smile.jpgの画像にコピーを入れ、その後、レイアウトに書きます:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/smile"
/>
5.その他のコントロール
私が展開して放課後の学生に、そんなに話を自分自身を開始しません
1.CheckBoxボックスを:https://blog.csdn.net/kotlp1/article/details/78886736
2.ProgressBarプログレスバー:HTTPS:// www.jianshu.com/p/f613571addb5
すぎて、自分自身を拡張するために、学生の将来のニーズに応じて
第二に、基本的なレイアウト
1.LinearLayout(線形レイアウト)
レイアウト、HA、直鎖状、直鎖状、線と同じ特性を有する線形ものです。
LinearLayoutは垂直型内部の構成を制御するための制御の2つのモードがあり(アンドロイド:オリエンテーション=「垂直」 )、 一方が水平モードである(アンドロイド:オリエンテーション=「水平」 )、 我々は、モードを設定する場合垂直モードは、携帯電話の画面上で、コントロールはダウン内部に垂直に配置され、各行は、我々は、水平モード、携帯電話の画面を設定する場合、このレイアウトは一列であるが有していてもよく、一方のみの制御を有する場合行のコントロールの数。
アンドロイド:方位属性は配列方向を指定する指定された水平方向の場合、制御は、水平方向に配置され、垂直です。
アンドロイド:重力をコントロール内のテキストの整列を指定するために使用されている
アンドロイドを:layout_gravityは、レイアウト内の配向制御を指定するために使用されている
アンドロイド:代わっ間隔に、layout_weight =「1」(重量分布)、垂直レイアウトの重量と、代表的な列幅のレベルとき、
アンドロイド:視認性=不可視制御レイアウトが表示されている:1、2可視表示は、表示されたが、3空間は目に見えない、なくなっ隠されていません
ボタンの垂直方向の配置
レンダリング
<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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
android:textAllCaps="false"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2"
android:textAllCaps="false"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button3"
android:textAllCaps="false"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button4"
android:textAllCaps="false"/>
</LinearLayout>
アンドロイドを使用する必要がある3、それを達成する方法であるフルスクリーン幅、::layout_weight我々は、画面を水平にしたい場合は1の比率となるように二つのボタンリニアレイアウト、コントロールは、隣接しています
<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="horizontal"
tools:context=".MainActivity">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
android:textAllCaps="false"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="button2"
android:textAllCaps="false"/>
</LinearLayout>
2.RelativeLayout(対向配置)
フロント基本位置制御のどの位置制御に依存し、最も一般的な構成である制御の相対的な配置位置は、後者の相対位置に応じて算出され、レイアウトが最も柔軟性があります。
1.図の効果を達成するために。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="button1"
/>
<Button
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="button1"
/>
</RelativeLayout>
図2は、結果を達成します:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_toLeftOf="@+id/button1"
android:text="button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="button1"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_toLeftOf="@+id/button1"
android:text="button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="button1"
/>
</RelativeLayout>
3.RelativeLayout制御測位属性対向し、アンドロイドのさらに別のセットにおいて:左端と他のコントロール整列、アンドロイドの左端になるように制御を示すlayout_alignLeft:制御を示すlayout_alignRightよう右端と他のコントロールlayout_alignBottomとAndroid:右端、アンドロイドを揃えるlayout_alignTopが同じ理由で、あなたが探検し所有することになります!
3.FrameLayout(フレームのレイアウト)
事前に良い本のような画面の空の領域上でframeLayoutオブジェクトは、いくつかの要素は、写真など、内部に充填することができます。全ての要素が領域でframeLayout上部左端の領域に配置されているが、これらの要素の正確な位置を指定することはできません複数の要素は、要素の背後にある要素が前面に重ねて表示される場合、形成されています。
レンダリング:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="hello world !!! "/>
</FrameLayout>
4.その他のレイアウト
TableLayout(テーブルレイアウト)、AbsoluteLayout(レイアウトの絶対位置)などを調べるために、自分のデータにアクセスするために行くことができます
III。ジョブズ
図は、次のような効果を達成します:
ジョブ概要:画像は異なっていても、同じ位置に制御することができます。[表示]ボタンをクリックして、答えを入力しEDITTEXT、答えは次のTextViewに表示されます