1. Margin_Padding


인터넷에서 300 x 200 이미지를 다운로드 받아서 drawable에 넣어주세요.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="org.android.soldesk.margin_padding_1.Margin_Padding_1Activity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#88ff0000"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button01"
android:layout_margin="2pt"
android:padding="2pt"
android:text="마진 : 2 패딩 : 2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button011"
android:layout_margin="2pt"
android:padding="2pt"
android:text="마진 : 2 패딩 : 2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button012"
android:layout_margin="2pt"
android:padding="2pt"
android:text="마진 : 2 패딩 : 2"
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#8800ff00"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button02"
android:layout_margin="8pt"
android:padding="8pt"
android:text="마진 : 8 패딩 : 8"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button021"
android:layout_margin="8pt"
android:padding="8pt"
android:text="마진 : 8 패딩 : 8"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button022"
android:layout_margin="8pt"
android:padding="8pt"
android:text="마진 : 8 패딩 : 8"
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff0000ff"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button03"
android:layout_margin="5pt"
android:padding="20pt"
android:text="마진 : 5 패딩 : 20"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Image01"
android:adjustViewBounds="true"
android:tint="#88dddd33"
android:src="@drawable/a"
/>
</LinearLayout>
</LinearLayout>



2. Checkbox(체크박스)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="org.android.soldesk.checkbox_01.Checkbox_01Activity">

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkA"
android:text="AA"
/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkB"
android:text="BB"
/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkC"
android:text="CC"
/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkD"
android:text="DD"
/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkE"
android:text="EE"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtResult"
android:text="체크된 값 출력"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</LinearLayout>


package org.android.soldesk.checkbox_01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class Checkbox_01Activity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener{

CheckBox chkA;
CheckBox chkB;
CheckBox chkC;
CheckBox chkD;
CheckBox chkE;
TextView txtResult;

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

chkA = (CheckBox) findViewById(R.id.chkA);
chkB = (CheckBox) findViewById(R.id.chkB);
chkC = (CheckBox) findViewById(R.id.chkC);
chkD = (CheckBox) findViewById(R.id.chkD);
chkE = (CheckBox) findViewById(R.id.chkE);

txtResult = (TextView) findViewById(R.id.txtResult);

chkA.setOnCheckedChangeListener(this);
chkB.setOnCheckedChangeListener(this);
chkC.setOnCheckedChangeListener(this);
chkD.setOnCheckedChangeListener(new MyButtonHandler());
chkE.setOnCheckedChangeListener(new Aaa(this));
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

String str = "체크된 값 : ";

if (chkA.isChecked())
{
str += chkA.getText().toString();
}
if (chkB.isChecked())
{
str += chkB.getText().toString();
}
if (chkC.isChecked())
{
str += chkC.getText().toString();
}

txtResult.setText(str);

}

private class MyButtonHandler implements CompoundButton.OnCheckedChangeListener {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
String str = "체크된 값 : ";

if (chkD.isChecked())
{
str += chkD.getText().toString();
}

txtResult.setText(str);
}
}
}


package org.android.soldesk.checkbox_01;


import android.widget.CompoundButton;


/**
* Created by soldesk on 2017-03-17.
*/


class Aaa implements CompoundButton.OnCheckedChangeListener {

Checkbox_01Activity chk = null;

public Aaa(Checkbox_01Activity kkk) {

chk = kkk;

}

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
String str = "체크된 값 : ";

if (chk.chkE.isChecked())
{
str += chk.chkE.getText().toString();
}

chk.txtResult.setText(str);

}
}



3. Layout(레이아웃)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context="org.android.soldesk.layout_01.Layout_01Activity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button01"
android:text="버튼 111"
android:background="#6600ff00"
/>

</LinearLayout>



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
tools:context="org.android.soldesk.layout_02.Layout_02Activity">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The"
android:textSize="5pt"
android:textColor="#ff0000"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="World"
android:textSize="10pt"
android:textColor="#00ff00"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="of Android"
android:textSize="15pt"
android:textColor="#0000ff"
/>
</LinearLayout>



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="org.android.soldesk.layout_03.Layout_03Activity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button01"
android:layout_weight="0"
android:text="글 등록"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView01"
android:layout_weight="0"
android:text="이름"
/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText01"
android:layout_weight="0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView02"
android:layout_weight="0"
android:text="의견"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText02"
android:layout_weight="1"
/>
</LinearLayout>



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.android.soldesk.framelayout_1.FrameLayout_1Activity">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView01"
android:src="@drawable/a"
android:tint="#8800ff00"
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button01"
android:text="여기를 누르세요"
/>

</FrameLayout>



<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.android.soldesk.tablelayout_01.Tablelayout_01Activity">
<TableRow>
<TextView android:text="주소"/>
<EditText android:text="서울시 종로구 관철동 101"/>

</TableRow>
<TableRow>
<TextView android:text="이름"/>
<EditText android:text="수선화"/>

</TableRow>
<TableRow>
<TextView android:text="전화번호"/>
<EditText android:text="010-1234-5678"/>

</TableRow>
<TableRow>
<Button android:text="저장"/>
<Button android:text="취소"/>

</TableRow>

<Button android:text="완료"/>
</TableLayout>



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.android.soldesk.relativelayout_01.RelativeLayout_01Activity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/address"
android:layout_alignParentTop="true"
android:text="주소를 입력하세요"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/input"
android:background="@android:drawable/editbox_background"
android:layout_below="@+id/address"
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cancel"
android:layout_below="@+id/input"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:text="취소"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/a"
android:layout_toRightOf="@+id/cancel"
android:layout_alignTop="@+id/cancel"
android:layout_marginRight="10dp"
android:text="확인"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/a"
android:layout_alignTop="@+id/a"
android:text="Name"
/>

</RelativeLayout>



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/layoutManager"
tools:context="org.android.soldesk.layoutbycode_01.LayoutByCode_01Activity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button01"
android:text="버튼011"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button02"
android:text="버튼0222"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button03"
android:text="버튼03333"
/>

</LinearLayout>
package org.android.soldesk.layoutbycode_01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;

public class LayoutByCode_01Activity extends AppCompatActivity {

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

LinearLayout manager = (LinearLayout) findViewById(R.id.layoutManager);
manager.setOrientation(LinearLayout.HORIZONTAL);

Button button = (Button) findViewById(R.id.button01);
button.setText("아름다운 꽃");
}
}



org.android.soldesk.layoutparam_01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;

public class LayoutParam_01Activity extends AppCompatActivity {

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

LinearLayout manager = new LinearLayout(this);

manager.setOrientation(LinearLayout.VERTICAL);

Button button01 = new Button(this);
Button button02 = new Button(this);
Button button03 = new Button(this);


button01.setText("첫번째 버튼");
button02.setText("두두번째 버튼");
button03.setText("세세세번째 버튼");


LinearLayout.LayoutParams param1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);

LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);

LinearLayout.LayoutParams param3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);


manager.addView(button01,param1);
manager.addView(button02,param2);
manager.addView(button03,param3);

setContentView(manager);



<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.android.soldesk.absolutelayout_01.AbsoluteLayout_01Activity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="200px"
android:layout_y="200px"
android:text="(200,200)"
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="300px"
android:layout_y="400px"
android:text="(300,400)"
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="-50px"
android:layout_y="150px"
android:text="(-50,150)"
/>

</AbsoluteLayout>



4. Toggle(토글)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="org.android.soldesk.togglebutton_01.ToggleButton_01Activity">

<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnToggle"
android:textOn="켜짐"
android:textOff="꺼꺼짐"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtResult"
android:text="토글 버튼의 상대 값 출력"
android:textAppearance="?android:attr/textAppearanceLarge"
/>

<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnToggle1"
android:textOn="켜짐"
android:textOff="꺼꺼짐"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtResult1"
android:text="토글 버튼의 상대 값 출력"
android:textAppearance="?android:attr/textAppearanceLarge"
/>

</LinearLayout>
package org.android.soldesk.togglebutton_01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;

public class ToggleButton_01Activity extends AppCompatActivity {

ToggleButton toggle;
TextView txtResult;
TextView txtResult1;
ToggleButton toggle1;

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

txtResult = (TextView) findViewById(R.id.txtResult);
toggle = (ToggleButton) findViewById(R.id.btnToggle);
txtResult1 = (TextView) findViewById(R.id.txtResult1);
toggle1 = (ToggleButton) findViewById(R.id.btnToggle1);

toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if(isChecked)
{
txtResult.setText("켜짐 상태~~~~");
}
else
{
txtResult.setText("꺼꺼짐 상태 @@@@");
}


}
});

toggle1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {



if(isChecked)
{
txtResult1.setText("대한민국 만세");
}
else
{
txtResult1.setText("홍길동 만세");
}
}
});
}
}



5. radioButton(라디오버튼)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="org.android.soldesk.radiobutton_1.RadioButton_1Activity">



<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup01"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio01"
android:checked="true"
android:text="사과"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio02"
android:text="바나나"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio03"
android:checked="true"
android:text="복숭아"
/>

</RadioGroup>

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup02"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio011"
android:checked="true"
android:text="사과"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio022"
android:text="바나나"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio033"
android:checked="true"
android:text="복숭아"
/>

</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtResult"
android:text="선택한 RadioButton"
android:textAppearance="?android:attr/textAppearanceLarge"
/>

</LinearLayout>
package org.android.soldesk.radiobutton_1;

import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioGroup;
import android.widget.TextView;

public class RadioButton_1Activity extends AppCompatActivity {

RadioGroup group;
RadioGroup group1;
TextView txtResult;

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

txtResult = (TextView) findViewById(R.id.txtResult);
group = (RadioGroup) findViewById(R.id.radioGroup01);
group1 = (RadioGroup) findViewById(R.id.radioGroup02);

group1.setOnCheckedChangeListener(new Aaa(this));


group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {

switch (checkedId)
{
case R.id.radio01:

txtResult.setText("사과~~~~");
Log.i("MyButton", "사과~~~~");
break;

case R.id.radio02:

txtResult.setText("바나나^^^^");
Log.i("MyButton", "바나나^^^^");
break;

case R.id.radio03:

txtResult.setText("복숭아$$$$$$$$");
Log.i("MyButton", "복숭아$$$$$$$$");
break;
}
}
});
}
}
package org.android.soldesk.radiobutton_1;

import android.support.annotation.IdRes;
import android.util.Log;
import android.view.View;
import android.widget.RadioGroup;

/**
* Created by soldesk on 2017-03-17.
*/

class Aaa implements RadioGroup.OnCheckedChangeListener {
RadioButton_1Activity chk = null;
public Aaa(RadioButton_1Activity kkk){
chk = kkk;
}

@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {

switch (checkedId)
{
case R.id.radio011:

chk.txtResult.setText("사과!!!");
Log.i("MyButton", "사과!!!");
break;

case R.id.radio022:

chk.txtResult.setText("바나나~~~");
Log.i("MyButton", "바나나~~~");
break;

case R.id.radio033:

chk.txtResult.setText("복숭아******");
Log.i("MyButton", "복숭아******");
break;
}
}
}

+ Recent posts