activity_main.xml

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="26sp"
android:hint="x value"
android:inputType="numberSigned"/>
<EditText
android:id="@+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="26sp"
android:hint="y value"
android:inputType="numberSigned"/>
<Button
android:id="@+id/btn1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="toast meesage"
android:textSize="20sp"
android:onClick="onBtnClicked"/>
</LinearLayout>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "toast shape change"
android:onClick="onBtn2Clicked"
android:layout_gravity="center"
android:textSize="20sp"/>

toast_boarder.xml

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:padding="10dp"
android:background="@drawable/toast_background"/>

toast_background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="5dp"
android:color="#00f"/>
<solid
android:color="#0ff"/>
<padding
android:left="20dp"
android:top="20dp"
android:right="20dp"
android:bottom="20dp"/>
<corners
android:radius="20dp"/>
</shape>

MainActivity.java

public class MainActivity extends AppCompatActivity {
EditText editText1;
EditText editText2;

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

editText1 = findViewById(R.id.editText1);
editText2 = findViewById(R.id.editText2);
}
public void onBtnClicked(View v){
try {
Toast toast = Toast.makeText(context: this, text: "hahaha", Toast.LENGTH_LONG);
int xValue = Integer.parseInt(editText1.getText().toString());
int yValue = Integer.parseInt(editText2.getText().toString());
//입력된 좌표값을 가져온다
toast.setGravity(gravity: Gravity.TOP| Gravity.TOP, xValue, yValue);
toast.show();
}catch(NumberFormatException e){
e.printStackTrace();
}
}
//toast message 모양 바꾸기
public void onBtn2Clicked(View v){
LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.toast_boarder, (ViewGroup)findViewById(R.id.toast_layout));

TextView textView = layout.findViewById(R.id.textView);

Toast toast = new Toast(context: this);
textView.setText("style changed toast");
toast.setGravity(Gravity.CENTER, xOffset: 0, yOffset: -50);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);

toast.show();
}
}

'android studio' 카테고리의 다른 글

카드뷰(CardView)  (0) 2019.08.12
버튼 style변경(onDraw(), invalidate())  (0) 2019.08.12
inflation  (0) 2019.08.11
GridView  (0) 2019.08.11
Spinner  (0) 2019.08.10

layout은 화면구성을 정의해놓은 파일로

화면에 보여지도록 하기위해 java code가 필요하다

*.xml에서 정의한 layout을 Inflater를 통해 객체화를하고

객체화를 한후 *.java를 통해 화면에 보이도록 한다.

 

setContentView(R.layout.*) method를통해

화면에 보여줄 view를 지정(매개변수) 하고

객체화(memory loading)을 한다

R은 app/res를 의미한다

 

setContentView 는 전체화면만 객체화를하고

LayInflater를 통해 부분작업 객체화를 한다

activity_main.xml

<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="inflation test"
android:layout_marginTop = "30dp"
android:textSize = "30sp"
android:textColor = "#a63"
android:layout_gravity = "center"/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text = "add layout"
android:textSize = "30sp"
android:onClick="onClickedBtn"/>
<LinearLayout
android:id="@+id/addLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

add_layout.xml

<Button
android:id="@+id/btnTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "test"
android:textSize = "20sp"
android:textStyle = "bold"/>
<RadioGroup
android:id="@+id/radioGroup"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<RadioButton
android:id="@+id/radioBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sport"
android:textColor="#00f"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginRight="5dp"/>
<RadioButton
android:id="@+id/radioBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="travel"
android:textColor="#00f"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginRight="5dp"/>
<RadioButton
android:id="@+id/radioBtn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="reading"
android:textColor="#00f"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginRight="5dp"/>
<RadioButton
android:id="@+id/radioBtn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gaming"
android:textColor="#00f"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginRight="5dp"/>
</RadioGroup>
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_margin="10dp"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="accept"
android:textSize="20sp"
android:layout_margin="10dp"
android:textColor="#f00"/>
<CheckBox
android:id="@+id/agree"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//전체화면에 대한 뷰를 지정하고, inflation을 한다
}
//when button is clicked, add layout
public void onClickedBtn(View v){
addLayout();
}
//add_layout.sml을 activity_main.xml에 추가하는 기능의 method
private void addLayout(){
LinearLayout parentLayout = findViewById(R.id.addLayout);

//inflation
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.add_layout, parentLayout, true);

Button btnTest = findViewById(R.id.btnTest);
final CheckBox agree = findViewById(R.id.agree);

btnTest.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
if(agree.isChecked()){
agree.setChecked(false);
}else{
agree.setChecked(true);
}
}
});
}
}

'android studio' 카테고리의 다른 글

버튼 style변경(onDraw(), invalidate())  (0) 2019.08.12
toast message, style  (0) 2019.08.11
GridView  (0) 2019.08.11
Spinner  (0) 2019.08.10
AdapterView(ListView)  (0) 2019.08.10

activity_main.xml

<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:padding="10dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="20dp"
android:gravity="center">
</GridView>

CustomAdapter.java

public class CustomAdapter extends BaseAdapter {
//BaseAdapter를 상속받는다
private Context mContext;
private int[] data;

public CustomAdapter(Context mContext, int[] data){
this.mContext = mContext;
this.data = data;
}

public int getCount(){
return data.length;
}//getCount method를 통해 data의 갯수를 얻어온다
public Object getItem(int position){
return data[position];
}
public long getItemId(int position){
return position;
}

public View getView(int position, View convertView, ViewGroup parent){
ImageView imageView;

if(convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(w: 150, h: 150));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(left: 5, top: 5, right: 5, bottom: 5);
}else{
imageView = (ImageView)convertView;
}
imageView.setImageResource(data[position]);
return imageView;
}
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

private int[] imgData = {R.drawable.apple, R.drawable.apple,
R.drawable.apple, R.drawable.apple, R.drawable.apple, R.drawable.apple,
R.drawable.apple, R.drawable.apple, R.drawable.apple, R.drawable.apple,
R.drawable.apple, R.drawable.apple, R.drawable.apple, R.drawable.apple};
private CustomAdapter adapter;
private GridView gridView;

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

adapter = new CustomAdapter(mContext: this, imgData);

gridView = findViewById(R.id.gridView);
gridView.setAdapter(adapter);
}
}

--------------------

activity_main.xml

<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:padding="10dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="20dp"
android:gravity="center">
</GridView>

Grid_item.java

public class Grid_item {
String apple;
int resId;

public Grid_item(String apple, int resId){
this.apple = apple;
this.resId = resId;
}

public String getApple(){
return apple;
}
public void setApple(String apple){
this.apple = apple;
}
public int getResId(){
return resId;
}
public void setResId(int resId){
this.resId = resId;
}
}

item_style.xml

<ImageView
android:id="@+id/imgView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/apple"/>
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="apple"
android:textColor="#5505ff"
android:textStyle="bold"
android:layout_gravity="center"/>

GridItemView.java

public class GridItemView extends LinearLayout {
ImageView imageView;
TextView textView;

public GridItemView(Context context){
super(context);
init(context);
}
public void init(Context context){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.item_style, this, true);

imageView = findViewById(R.id.imgView);
textView = findViewById(R.id.txtView);
}
public void setImage(int resId){
imageView.setImageResource(resId);
}
public void setApple(String apple){
textView.setText(apple);
}
}

CustomAdapter.java

public class CustomAdapter extends BaseAdapter {
//BaseAdapter를 상속받는다
private Context mContext;
ArrayList<Grid_item> data = new ArrayList<Grid_item>();

public CustomAdapter(Context mContext){
this.mContext = mContext;
}

public void addItem(Grid_item grid_item){
data.add(grid_item);
}

public int getCount(){
return data.size();
}//getCount method를 통해 data의 갯수를 얻어온다
public Object getItem(int position){
return data.get(position);
}
public long getItemId(int position){
return position;
}

public View getView(int position, View convertView, ViewGroup parent){

GridItemView view = new GridItemView(mContext);
Grid_item item = data.get(position);

view.setImage(item.getResId());
view.setApple(item.getApple());

return view;
}
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

private CustomAdapter adapter;
private GridView gridView;

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

gridView = findViewById(R.id.gridView);

adapter = new CustomAdapter(this);
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));
adapter.addItem(new Grid_item("apple", R.drawable.apple));

gridView.setAdapter(adapter);
}
}

'android studio' 카테고리의 다른 글

toast message, style  (0) 2019.08.11
inflation  (0) 2019.08.11
Spinner  (0) 2019.08.10
AdapterView(ListView)  (0) 2019.08.10
view에 도형, 텍스트 그리기  (0) 2019.08.10

activity_main.xml

<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80f0"
android:gravity="center"
android:text="country"
android:textSize="30dp" />
<Spinner
android:id="@+id/sp01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" />

MainActivity.java

public class MainActivity extends AppCompatActivity {
TextView textView;
Spinner spinner;
ArrayAdapter<String> adapter = null;

String[] items = {"korea", "china", "japan", "france"};

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

textView = findViewById(R.id.txt);
spinner = findViewById(R.id.sp01);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter(adapter);
}
}

---seperate data---

activity_main.xml

<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80f0"
android:gravity="center"
android:text="country"
android:textSize="30dp" />
<Spinner
android:id="@+id/sp01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" />

country.xml

<string-array name="country">
<item>korea</item>
<item>china</item>
<item>japan</item>
<item>france</item>
</string-array>

MainActivity.java

public class MainActivity extends AppCompatActivity {

Spinner spinner;
ArrayAdapter<CharSequence> adapter = null;

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

spinner = findViewById(R.id.sp01);
adapter = ArrayAdapter.createFromResource(this, R.array.country, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter(adapter);
}
}

'android studio' 카테고리의 다른 글

inflation  (0) 2019.08.11
GridView  (0) 2019.08.11
AdapterView(ListView)  (0) 2019.08.10
view에 도형, 텍스트 그리기  (0) 2019.08.10
Button, RadioButton, CheckBox, ImageView, ImageButton  (0) 2019.08.10

Adapter가 data를 가져와서 getview() method를 통해 Adapter View형태로 보여준다

Adapter의 종류에는 ArrayAdapter, SimpleAdapter, cursorAdapter가 있다

Adapter View의 종류에는 ListView, GridView, Spinner, Gallery등이 있다

 

activity_main.xml

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>

MainActivity.java

public class MainActivity extends AppCompatActivity {

ArrayList<String> arrayList = null;
ArrayAdapter<String> adapter = null;
ListView listView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

arrayList = new ArrayList<String>();
arrayList.add("jusung");
arrayList.add("aaaaa");
arrayList.add("bbbbb");
arrayList.add("ccccc");
arrayList.add("ddddd");
arrayList.add("eeeee");
arrayList.add("fffff");
arrayList.add("ggggg");
arrayList.add("hhhhh");
arrayList.add("iiiii");
arrayList.add("jjjjjj");

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);

listView = findViewById(R.id.listView);
listView.setAdapter(adapter);
//adapter를 통해 화면에 보여준다
}

}

---seperate data---

activity_main.xml

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>

 

MainActivity.java

public class MainActivity extends AppCompatActivity {

ArrayAdapter<CharSequence> arrayAdapter = null;
ListView listView = null;

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

//createFromResource() method를 이용해 resource로부터 adapter를 생성
arrayAdapter = ArrayAdapter.createFromResource(this, R.array.contact, android.R.layout.simple_list_item_checked);
//ctr+space bar를 눌러서 다른 목록을 선택할수있다.
listView = findViewById(R.id.listView); //listView를 가져온다
listView.setAdapter(arrayAdapter);

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
//listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
//multiple일때 여러개 선택가능하다

//ColorDrawable객체를 이용해 구분선에 색을추가할수있다
ColorDrawable colorDrawable = new ColorDrawable(Color.BLUE);
listView.setDivider(colorDrawable);
listView.setDividerHeight(5);
}

}

data.xml

//res\values\data.xml

<resources>
<string-array name="contact">
<item>fffff 010010010</item>
<item>eeeee 010010010</item>
<item>ddddd 010010010</item>
<item>ccccc 010010010</item>
<item>bbbbb 010010010</item>
<item>aaaaa 010010010</item>
</string-array>
</resources>

---listActivity---

MainActivity.java

public class MainActivity extends ListActivity {
//ListActivity를 상속받는다
ArrayList<String> data = null;
ArrayAdapter<String> adapter = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
//ListActivity에 listView가 포함되있다

data = new ArrayList<String>();
data.add("aaaaa");
data.add("bbbbb");
data.add("ccccc");
data.add("ddddd");
data.add("eeeee");
data.add("fffff");
data.add("ggggg");
data.add("hhhhh");
data.add("iiiii");

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);

setListAdapter(adapter);
//ListActivity에 setListAdapter method를 이용해 adapter를 추가시킨다
}
}

---listActivity---

MainActivity.java

public class MainActivity extends ListActivity {
//ListActivity를 상속받는다
String[] laughing = {"haha","hoho","hihi","hehe","huhu","hwhw"};
ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
//ListActivity에 listView가 포함되있다

adapter = new ArrayAdapter<String>(this, R.layout.activity_list_style,
R.id.laugh, laughing);
//직접만든 activity_list_style로 지정한다
//actvity_list_style에 만든 text view의 id값에 data laughing를 입력한다

setListAdapter(adapter);
//ListActivity에 setListAdapter method를 이용해 adapter를 추가시킨다
}
}

activity_list_style.xml

//res\layout에 activity_list_style.xml를 만든다

<ImageView
android:id="@+id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_foreground"/>
<TextView
android:id="@+id/laugh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:paddingTop="50dp"/>

'android studio' 카테고리의 다른 글

GridView  (0) 2019.08.11
Spinner  (0) 2019.08.10
view에 도형, 텍스트 그리기  (0) 2019.08.10
Button, RadioButton, CheckBox, ImageView, ImageButton  (0) 2019.08.10
text view  (0) 2019.08.09

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
// 주석처리해준다

Custom custom = new Custom(this);
setContentView(custom);
//custom 객체 생성후 불러온다
}

Custom.java


public class Custom extends View {
//View를 상속받는다
private Paint paint;

public Custom(Context context){
super(context);
}//view class에 context호출하는 생성자생성

protected void onDraw(Canvas canvas){
canvas.drawColor(Color.CYAN);
//CYAN color의 도화지생성

paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3.0F);
//STROKE는 테두리를 나타내고 default값은 FILL이다
paint.setColor(Color.GREEN);
canvas.drawCircle(500, 500, 300, paint);
//x,y 좌표 500에 300 반지름의 green 원이 생긴다

paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.MAGENTA);
canvas.drawCircle(500, 500, 300, paint);
//위에 원과 겹쳐 원에 테두리가 있는것처럼보인다

paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.BLUE);
paint.setARGB(255,255,0,0);
//a는 0~255사이의값으로 투명도를 나타낸다
canvas.drawRect(10,10,200,200,paint);
//왼쪽 상단과 오른쪽 상단의 좌표를 지정한다

paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(10.0F);
//STROKE로 설정할경우 테두리가그려진다
paint.setColor(Color.BLUE);
paint.setARGB(255,0,255,0);
canvas.drawRect(10,210,200,400,paint);

DashPathEffect dashPathEffect = new DashPathEffect(new float[]{5,5}, 1);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(10.0F);
paint.setPathEffect(dashPathEffect);
//점선을 만든다
paint.setColor(Color.BLUE);
canvas.drawRect(220,210,400,410,paint);

//TEXT
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(100);
canvas.drawText("it is jusung", 300, 900,paint);
}
}

'android studio' 카테고리의 다른 글

Spinner  (0) 2019.08.10
AdapterView(ListView)  (0) 2019.08.10
Button, RadioButton, CheckBox, ImageView, ImageButton  (0) 2019.08.10
text view  (0) 2019.08.09
android layout  (0) 2019.08.07

----Button, RadioButton, CheckBox----

activity_main.xml

<TextView
android:id="@+id/txt01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pay now"
android:textSize="25sp"
android:layout_margin="10dp"/>
<RadioGroup
android:id="@+id/rGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rBtn01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Card"
android:textSize="25sp"
android:textColor="#33aa88"
android:textStyle="bold"/>
<RadioButton
android:id="@+id/rBtn02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="phone"
android:textSize="25sp"
android:textStyle="bold"
android:textColor="#33aa88"/>
<RadioButton
android:id="@+id/rBtn03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="bank"
android:textSize="25sp"
android:textStyle="bold"
android:textColor="#33aa88"/>
</RadioGroup>
<!--버튼이 하나씩만 작동할수 있게 하려면 RadioGroup으로 묶어줘야한다-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="30dp"
android:gravity="right">
<CheckBox
android:id="@+id/chkBox01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="accept terms"
android:textSize="20sp"
android:layout_marginRight="45dp"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pay now"
android:textSize="25sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"/>

----imageView----

image file을 res\drawable에 저장후

@drawable/file_name(only lowercase)을 이용해 불러올수있다

activity_main.xml

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hey"
android:maxWidth="300dp"
android:adjustViewBounds="true"/>
<!--크기 조절을위해선 layout크기를 wrap_content로 해야하고
adjustViewBoudns에 true값을 줘야한다-->
<!--maxHeight 값을 입력안할시 가로비율에맞춰 크기가조정된다=-->
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/hey"
android:scaleType="matrix"/>
<!--scaleType을 설정하지 않을경우 사진이 중앙으로
가로, 세로비율이 자동으로 조절되서 오게된다
scaleType="fitXY"로 설정할경우 화면 크기로 image size가 조절된다
fitXY로 설정후 Width와 Height값을통해 사진크기를 조절할수있다-->

----image button---

activity_main.xml

<ImageButton
android:id="@+id/imgBtn"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/button"
android:contentDescription="turn off"
android:layout_gravity="center"/>
<!--src로 img를 불러올경우 border이 생겨서 background로 불러온다-->
<!--contentDescription을통해 button설명글을 추가할수있다-->

 

'android studio' 카테고리의 다른 글

AdapterView(ListView)  (0) 2019.08.10
view에 도형, 텍스트 그리기  (0) 2019.08.10
text view  (0) 2019.08.09
android layout  (0) 2019.08.07
Custom ListView  (0) 2019.08.07

----text view----

1. activity_main.xml

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="30sp" />
<!--app, res, values, strings.xml에서 text를 따로 관리할수있다
string tag와 name을 이용해 불러올수있다-->
<!--text color는 #AARRGGBB 로 정의할수있다
AA는 투병도로 00은 완전투명 77는 반투명 FF는 완전불투명-->

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test"
android:textSize="30sp" />
<!--다국어로 이용할경우 resource안에
values-en/strings.xml, values-ko/string.xml 와같이 만든후
단말기 setting으로 각 언어를 불러올수있다-->

<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/marquee"
android:textSize="30sp"
android:singleLine="true"
android:focusable="true"
android:ellipsize="marquee"/>

<!--android:singleLine="true"를 할경우 뒷부분이 ...으로 한줄에 표시된다 -->
<!--android:ellipsize="start, middle, end, marquee"로 뒷부분 ...을 조정가능-->

<!--marquee 속성을 이용하려면 singleline, focusable 값에 true를 설정하고
java코드를 작성해준다. marqueeRepeatLimit="forever"를통해 반복횟수를 조절할수있다-->

<!--android:maxLines="1"을 이용해 표시될 줄을 설정할수있다-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sndroid"
android:textSize="70sp"
android:textStyle="bold|italic"/>
<!--android:typeface="serif, sans, monospace"와 같이 지정할수있고
android:fontFamily="sans-serif"와 같이 글꼴을 지정할수도있다-->
<!--android:textStyle="Normal, Bold, Italic" 과같이 변경할수있다
두가지의 style을 적용할경우 | 를 이용한다-->

</LinearLayout>

 

2. strings.xml

<resources>
<string name="app_name">My Application</string>
<string name="test">test</string>
<string name="marquee">testtesttestsetsetsetstsetsetsetestsetsetestest</string>
</resources>

<!--name을 설정후 TextView를 이용해 사용할수있다-->

 

3. MainActivity.java

TextView textView;

textView = findViewById(R.id.txtView);
textView.setSelected(true);

<!--marquee 옵션이 작동할수있게 한다-->

 

----edit text-----

activity_main.xml

<EditText
android:id="@+id/nameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:inputType="text"
android:hint="put your name"/>
<!--input Type 설정시 키보드가 알맞게 변경된다-->

<!--inputType="number" or "textEmailAddress 가올수있다-->

'android studio' 카테고리의 다른 글

AdapterView(ListView)  (0) 2019.08.10
view에 도형, 텍스트 그리기  (0) 2019.08.10
Button, RadioButton, CheckBox, ImageView, ImageButton  (0) 2019.08.10
android layout  (0) 2019.08.07
Custom ListView  (0) 2019.08.07

+ Recent posts