목록만....

Webview 이어서...
이미지처리는 나중에 해결

뭐 많이 함...
어휴
파일 새로 만들
assets
html
imagpes
++ 안드로이드 웹 뷰에서 자스함수 호출
코드 추가(이거 webview19에서 한 듯)


TouchEvent
drowavle에 넣어놓고
바인딩해줌
터치이벤트발생 확인
사인하는 이벤트 만들거


optionmenu
new resourx directoy에서 폴더 맏늘기

contextmenu


-다이얼로그

'학원 > ANDROID' 카테고리의 다른 글

0109  (1) 2023.01.11
01/06 78-3[Android] compoundbutton  (1) 2023.01.07
01/06 78-2[Android] clockpicker  (1) 2023.01.07
01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07

팀플하느라 안드로이드 밀림....그래도

정리할 목록...은 남겨놔야

주말에... 할 수 있을 거같아서..

1.autocomplete 
   자동완성기능 구현
values에 strings 우선 하드코딩
(원래데이터는 서버에 요청해서 가져와야함 )


2.RatingBar
평가(별점) 하기
테마에 custom하고
manifest에 theme 변경
==> 실행 안됨... 이거 theme잘못 변경햇나봄

3.ScrollView
스크롤뷰 안에는 뷰(자식태그?)가 하나여야 함!
theme 변경(버튼색깔 변경)

4.ViewFlipper
https://www.iconfinder.com/search?q=android&price=free
아이콘 다운받아서 
res > drawable 에 넣어놔
자동으로 화면 전환하기
위젯 하나씩만 플립핑 됨
  처음 기술한 위젯(혹은 레이아웃)이
   제일 먼저 화면에 표시됨
  자바코드로 플립핑 해야함
오 얘는 뒤로 쌓이네?
플리핑은 받드시 자바코드로 코딩 해줘야 적용이 된다
얘도 바인딩 씀

5.IndicatorLayout
 이건 걍 하는 법만 ...

6.TebLayoutViewPager
    텝메뉴 구현
그리들에 dependencies 안에 
 implementation("com.tbuonomo:dotsindicator:4.3") 나
넣어놓기
 app:tabGravity="fill"
이러면 텝들이 균등하게 배열됨
프래그먼트: 
ViewPager2 뷰를 페이징 하는는 페이저
바인딩 넣어놓고
view 패키지 생성 
> class
layout 에도 xml 파일 3개 생성
뷰에 fragmen
BlankFragment
.model 패키지도 생성
> MyPagerAdapter클래스 생성
도통모르겠음


7.webview?
(ex. 가상전시관, 이미지보정)
바인딩
spring에서주소따옴
매니페스트에서 추가
<uses-permission android:name="android.permission.INTERNET "/>

'학원 > ANDROID' 카테고리의 다른 글

01/10  (0) 2023.01.11
01/06 78-3[Android] compoundbutton  (1) 2023.01.07
01/06 78-2[Android] clockpicker  (1) 2023.01.07
01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07


clockpicker,compoundbutton,radiobutton은 
radiogroup으로 감싸야 한다!
안 그럼 checkbox처럼
여러 개가 선택이 된다.


그리들에 

viewBinding {
            enabled = true
        }

바인딩 넣어놓고

 

activity_main

테마변경
<style name="Theme.CompoundButton12" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<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:padding="20dp"
    android:background="@drawable/layout_rounded"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <CheckBox
            android:id="@+id/check_politics"
            android:text="정치"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/check_economics"
            android:text="경제"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/check_entertainments"
            android:text="연예"
            android:checked="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/check_sports"
            android:text="스포츠"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <RadioGroup
            android:id="@+id/radioGroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
            <RadioButton
                android:id="@+id/radio_male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="남성" />
            <RadioButton
                android:id="@+id/radio_female"
                android:text="여성"
                android:checked="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <RadioButton
                android:id="@+id/radio_trans"
                android:text="트랜스젠더"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RadioGroup>
    </LinearLayout>
    <ToggleButton
        android:id="@+id/toggleButton"
        android:text="토글버튼(표시안됨 의미가 없음)"
        android:textOn="ON"
        android:textOff="OFF"
        android:checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Switch
        android:id="@+id/switch_button"
        android:text="블루투스"
        android:textOn="온(표시안됨)"
        android:textOff="오프(표시안됨)"
        android:checked="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <Button
        android:id="@+id/button"
        android:text="확인"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/textview"
        android:background="#8C69CA"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="10dp"
        android:lineSpacingExtra="5dp"
        android:textColor="@color/white"
        android:textStyle="bold"
        />
</LinearLayout>

values > strings.xml 에 리소스 넣어놓기

<resources>
    <string name="app_name">CompoundButton12</string>
    <string-array name="items" >
        <item>자바</item>
        <item>오라클</item>
        <item>HTML5</item>
        <item>CSS3</item>
        <item>자바스크립트(ES5)</item>
        <item>JSP/SERVLET</item>
        <item>STANDARD SPRING</item>
        <item>Mybatis</item>
        <item>SPRING REST API/SWAGGER</item>
        <item>JQUERY/AJAX</item>
        <item>부트스트랩4</item>
        <item>안드로이드</item>
    </string-array>

</resources>

res > darwable 에 layout 파일 넣어놓기(태두리모양 설)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/>
    <stroke android:width="5dp" android:color="#51B5AB" />
    <corners android:radius="10dp"/>

</shape>

 

MainActivity.java

public class MainActivity extends AppCompatActivity  implements CompoundButton.OnCheckedChangeListener {


    private ActivityMainBinding binding;
    //스피너 아이템 저장용
    private  String[] items;
    //[결과 출력을 위한 필드들]
    //체크박스
    private List<String> interestingLists = new Vector<>();
    //라디오버튼
    private String gender="남성";
    //스피너
    private String curiculumn="JSP/SERVLET";
    //토글버튼
    private String onOff="OFF";
    //스위치
    private String bluetooth="ON";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        //체크박스 제어
        binding.checkEntertainments.setChecked(false);
        binding.checkEconomics.setChecked(true);
        //최초 선택한값컬렉션에 저장
        interestingLists.add("경제");

        //라디오버튼제어
        //라디오 그룹으로 라디오버튼 체크 해제:clearCheck()
        binding.radioGroup.clearCheck();
        //라디오그룹으로 라디오버튼 체크 :check(리소스 아이디
        binding.radioGroup.check(R.id.radio_male);

        //토글버튼
        binding.toggleButton.setChecked(false);
        //스위치
        binding.switchButton.setChecked(true);
        //스피너에 아이템 설정하기
        items = getResources().getStringArray(R.array.items);
        ArrayAdapter<String> adapter=new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item,items);
        binding.spinner.setAdapter(adapter);
        //처음에 보여줄 아이템 선택:
        //xml속성에는 없음. absspinner클래스가 갖고있는 메소드
        binding.spinner.setSelection(5);

        //리스너 부착
        //체크박스랑 토글,스위치 버튼 두개는setOnCheckedChangeListener 이거 붙임
        //체크박스
        binding.checkEconomics.setOnCheckedChangeListener(this);
        binding.checkEntertainments.setOnCheckedChangeListener(this);
        binding.checkPolitics.setOnCheckedChangeListener(this);
        binding.checkSports.setOnCheckedChangeListener(this);
        //토글
        binding.toggleButton.setOnCheckedChangeListener(this);
        //스위치
        binding.switchButton.setOnCheckedChangeListener(this);

        //라디오버튼 - 라디오그룹에 리스너 부착하자 그리고 RadioGroup의 OnCheckedChangeListener
        //기타텀파운드 버튼들은 CompoundButton.OnCheckedChangeListener
        binding.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            //checkedid는체크된 라디오 버튼의 리소스 id값
            //radiogroup의 getchecked 주석가져왕
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                gender= ((RadioButton)findViewById(checkedId)).getText().toString();
                Log.i("com.kosmo.compound",gender+"선택");
            }
        });
        //스피너에는 setOnItemClickListener가 아니라 setOnItemSelectedListener를 붙여라.
        binding.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                /*
                    adapterView 여기서는spinner를 의미
                    view ; 하나의 아이템을표시하는덱스트뷰
                    position:The position of the view in the adapter
                    id:The row id of the item that is selected

                */
                Log.i("com.kosmo.compound",String.format("position:%s,id:%s",position,id));
                Log.i("com.kosmo.compound",String.format("커리큘럼:%s",items[position]));  //비추
                Log.i("com.kosmo.compound",String.format("커리큘럼:%s", ((TextView)view).getText()));
                curiculumn=((TextView)view).getText().toString();
            }
            
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {} //얘는 아무 일을하지 않음
        });
        //확인버튼 이벤트
        binding.button.setOnClickListener(view -> {
            binding.textview.setText(
                    String.format("체크박스:%s%n라디오박스:%s%n토글버튼:%s%n스위치:%s%n스피너:%s%n",
                            interestingLists,
                            gender,
                            onOff,
                            bluetooth,
                            curiculumn
                    ));
        });

    }//////////onCreate

    //CompoundButton걔열(체크박스/토글/스위치) 버튼 의 checked속성이 변경될 때마다 호출
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean ischecked) {
        Log.i("com.kosmo.compound","체크여부:"+ischecked);
        if(compoundButton instanceof CheckBox){
            if(ischecked){
                Log.i("com.kosmo.compound",compoundButton.getText()+"선택");
                interestingLists.add(compoundButton.getText().toString());
            }
            else {
                Log.i("com.kosmo.compound",compoundButton.getText()+"해제");
                interestingLists.add(compoundButton.getText().toString());

            }
        }
        else if(compoundButton.getId() == R.id.toggleButton){
            Log.i("com.kosmo.compound",ischecked? "토글 on" : "토글OFF");
            onOff=ischecked? "ON" : "OFF";
        }
        else {
            Log.i("com.kosmo.compound",ischecked? "블루투스 on" : "블루투스OFF");
            bluetooth=ischecked? "ON" : "OFF";
        }
    }

}///////MainActivity

어? 
checkEntertainments 아이디 설정한거랑 다름?
바인딩해서 클래스 만들 때 그렇게 바꾼대

 

 

 

'학원 > ANDROID' 카테고리의 다른 글

01/10  (0) 2023.01.11
0109  (1) 2023.01.11
01/06 78-2[Android] clockpicker  (1) 2023.01.07
01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07


참고로

ScrollView 안에  태그를  많이 넣으면 에러남요

 

AnalogClock랑   DigitalClock은
걍 전시용 이걸로 값을가져올 수는 없다!

activity_main

<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">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <AnalogClock
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"/>
        <DigitalClock
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_height="match_parent"/>
    </LinearLayout>
    <!--ScrollView 안에 여러개 테그 넣으면 에러남 -->
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
            <TimePicker
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:timePickerMode="spinner"
                />
            <DatePicker
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:datePickerMode="spinner"
                android:calendarViewShown="false"
                android:id="@+id/datePicker"
                />
        </LinearLayout>
    </ScrollView>

 

MainActivity

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DatePicker datePicker = findViewById(R.id.datePicker);
     /*방법1. 버전체크
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //API 레벨이26이상인 스마트 폰만 실행 됨
            datePicker.setOnDateChangedListener(new DatePicker.OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {

                }
            });
        }*/
        //방법2. 버전을 올린다. 그리들 모듈에서  minSdk 26로 변경 후 sync now 함!
        datePicker.setOnDateChangedListener(
                (Picker, year, month, dayOfMonth) ->
               //Toast.makeText(MainActivity.this, String.format("%s,%s,%s", year, month, dayOfMonth), Toast.LENGTH_SHORT).show()
            Log.i("com.kosmo.clockpicker",String.format("%s,%s,%s", year, month+1, dayOfMonth))
        );
    }

타이머 같은 기능 !

activity_main

※chronometer는 안드로이드에서 사용하는 아이디 고로
id로 설정하지 말아라

<Button
    android:id="@+id/btnTime"
    android:text="시간설정"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<Button
    android:id="@+id/btnDate"
    android:text="날짜설정"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<Chronometer
    android:id="@+id/timer_chronometer"
    android:textSize="20sp"
    android:textStyle="italic|bold"
    android:textColor="#BD3636"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="안드로이드 OS부팅후 흘러온 시간"
    android:id="@+id/btnElaspedTime"
    />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="타이머"
        android:textSize="50sp" />

    <Button
        android:id="@+id/btnStop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textview"
        android:layout_alignRight="@id/textview"
        android:text="중지" />

    <Button
        android:id="@+id/btnStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textview"
        android:layout_toLeftOf="@id/btnStop"
        android:text="시작" />
</RelativeLayout>

그리들에

viewBinding {
            enabled = true
        }

바인딩 넣어놓고

 

MainActivity

public class MainActivity extends AppCompatActivity implements View.OnClickListener, Chronometer.OnChronometerTickListener { //현재 클래스가 이벤트 핸들러가 됨

    //테마를 @style/Theme.Material3.Dark.Dialog로 변경
    private ActivityMainBinding binding;

    private TimePickerDialog timePickerDialog;
    private DatePickerDialog datePickerDialog;

    private Calendar calendar = Calendar.getInstance();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        //위젯에 리스너 부착
        binding.btnTime.setOnClickListener(this);
        binding.btnDate.setOnClickListener(this);
        binding.btnElaspedTime.setOnClickListener(this);
        binding.btnStart.setOnClickListener(this);
        binding.btnStop.setOnClickListener(this);
        binding.timerChronometer.setOnChronometerTickListener(this);

        //타임피커 타이얼로그 객체 생성
        /*
        context – the parent context
            themeResId – the resource ID of the theme to apply to this dialog
            listener – the listener to call when the time is set
            hourOfDay – the initial hour
            minute – the initial minute
            is24HourView – Whether this is a 24 hour view, or AM/PM.
        */

        timePickerDialog = new TimePickerDialog(
                this,
                android.R.style.Theme_Material_Dialog,
                (timePicker, hour, minute)->{
                    binding.textview.setText(String.format("%s시 %s분",hour,minute));
                },
                calendar.get(Calendar.HOUR),
                calendar.get(Calendar.MINUTE),
                true
        );
        /*
             context – the parent context
            listener – the listener to call when the user sets the date
            year – the initially selected year
            month – the initially selected month (0-11 for compatibility with Calendar.MONTH)
            dayOfMonth – the initially selected day of month (1-31, depending on month)
         */
        datePickerDialog = new DatePickerDialog(
                this,
                (datePicker,year,month,date) ->{
                    binding.textview.setText(String.format("%s년 %s월 %s일",year,month,date));
                },
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH)+1,
                calendar.get(Calendar.DATE)

        );

    }////////////////////////onCreate

    //요 밑에서 이벤트 구현
    //버든의 클릭 이벤트 용
    @Override
    public void onClick(View view) {
        if(view.getId()== R.id.btnTime){
            if(!timePickerDialog.isShowing())  timePickerDialog.show();
        }
        else if(view.getId()==R.id.btnDate){
            if(!datePickerDialog.isShowing())  datePickerDialog.show();
        }
        else if(view.getId()==R.id.btnElaspedTime){
            SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            Toast.makeText(this, dateFormat.format(new Date(SystemClock.elapsedRealtime())), Toast.LENGTH_SHORT).show();

        }
        else if(view.getId()==R.id.btnStart){
            //현재시간을 크로노미터의 기준 시간으로 설정
            binding.timerChronometer.setBase(SystemClock.elapsedRealtime());
            binding.timerChronometer.start();
        }
        else{
            binding.timerChronometer.stop();
        }
    }

    //크로노미터 틱 이벤트 용
    /*
    크로노미터는 디폴트로 분초로 표시됨
    아래코드 추가 시 시,분,초로 표시가능
    */

    //초가 변할때마다 자동으로 호출되는 콜백 메소드
    @Override
    public void onChronometerTick(Chronometer chronometer) {
        //크로미터를 시작한이후 플러온 시간
        long  elapsedTime =SystemClock.elapsedRealtime()-binding.timerChronometer.getBase();
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        binding.timerChronometer.setText(dateFormat.format(new Date(elapsedTime)));
    }
}

 

 

 

'학원 > ANDROID' 카테고리의 다른 글

0109  (1) 2023.01.11
01/06 78-3[Android] compoundbutton  (1) 2023.01.07
01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07
01/05 77-3 [Android] STYLE&THEME  (0) 2023.01.07

 

뷰를 커스텀하기

java > view > CustomView.java

이거 어디있나 한 참 찾았다..

//1.view 클래스 상속
public class CustomView extends View {

    //2.Context를 매개변수로 받은 생성자[자바코드용]
    public CustomView(Context context) {
        super(context);
        Log.i("com.kosmo.customview","뷰 객체로 화면 표시");
    }

    //2-1.context와 AttributeSet를 매개변수로 받는 생성자[xml용]
    public CustomView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        Log.i("com.kosmo.customview","xml로 화면 표시");
    }

    //3.onDraw()메소드 오버라이딩(마우슨 우클릭 Generate - 오버라이딩! )
    @Override
    protected void onDraw(Canvas canvas) {
       //배경색 설정
        canvas.drawColor(Color.CYAN);
        //붓 생성
        Paint paint = new Paint();
        paint.setAntiAlias(true);   //붓을 부드럽게 설정
        //붓 색상 설정
        paint.setColor(Color.RED);
        paint.setStrokeWidth(30); //단위는 픽셀, 붓 두깨
        //점 그리기
        canvas.drawPoint(100,100,paint);
        //선 그리기
        paint.setStrokeWidth(10);
        canvas.drawLine(150,150,500,150,paint);
        //사각형
        paint.setColor(0x88911740);
        canvas.drawRect(150,150,500,350,paint);
        //원그리기
        paint.setColor(Color.argb(255,0,255,0));
        canvas.drawCircle(250,450,100,paint);
        //이미지 그리기
        /*
            paint는 null 지정 그래야 이미지 원래 색대로 그려짐!
            원본크기 그대로 출력
            1.drawBitma(bitmap객체,x,y,pain객체)
        */
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_lock_airplane_mode_alpha);
     //   canvas.drawBitmap(bitmap,250,550,null);
        //2..drawBitma(bitmap객체,null,rect dest,Pain객체-null)
        //null지정시 원본이미지 전체가 선택된 후 확대 축소 가능

     //   canvas.drawBitmap(bitmap,null,new Rect(250,550,250+400,550+400),null);

        //3.drawBitmap(Bitmap객체,Rect src,Rect dest,Paint객체)
        //원본의 특정 부분 선택후 확대 축소
        canvas.drawBitmap(bitmap,new Rect(0,0,100,100),new Rect(250,550,250+400,550+400),null);
    }

stroke은 보더역할

 

기본 제공 이미지는  저기 저 경로로 가면 있음

 

 

activity_main.xml

<!--내가만든 뷰를 xml로 전개 시 -->
<com.kosmo.customview10_1.view.CustomView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</com.kosmo.customview10_1.view.CustomView>

 

태마도 

AndroidManifest.xml

android:theme="@style/Theme.CustomView10_1"

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //레이아웃 xml파일로 뷰 전개
        //setContentView(R.layout으로 시작하는리소스 아이디)
        setContentView(R.layout.activity_main);

        //내가만든 뷰로 전개
       // setContentView(new CustomView(this));
    }
}

 

자바코드로 버튼 제어하기

https://developer.android.com/topic/libraries/view-binding?hl=ko#java

findViewById대신 뷰 결합 사용(쟤는 같은 아이디 사용 시 충돌이 일어날 수 있는 문제가 있음)


뷰 바인딩 활성화 해야 함(설정파일에 설정 )

Gradle Scripts > buil.gradle(Mocule: ) 폴더 에

android{ } 요 안에!!

 

 viewBinding {
            enabled = true
        }

 

넣고 sync now 눌러준다

앱  한 번 실행하고 

좌측 상단 Android 를 Project탭으로 변경 후

app->build->generated->data_binding_~밑에 바인딩 클래스가 생성됨을 확인


ActivityMainBinding(그림참고) 

 

 

그 뒤로는 기억이 잘 안나서 순서가 뒤죽박죽임..... 나중에 시간있으면 

그때 순서 맞춰놔야겠다...

 

activity_main.xml 

<EditText
    android:hint="메시지를 입력하세요!"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/infoMessage"
    android:textSize="20sp"
    />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    >
    <Button
        android:id="@+id/btnShort"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="짧은 메시지"
        />
    <Button
        android:id="@+id/btnLong"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="긴 메시지"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"

        />
    <Button
        android:id="@+id/btnCustom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="커스텀뷰" />
</LinearLayout>

아직 아무 적용 x

 

MainActivity.java

 

rootView는 무조건 있음!  루트 뷰는 최상위 뷰(레이아웃)를 의미함!!

inflate() 가 setContentView 와 같음(전개하는 역할)

private ActivityMainBinding binding;
private ToastLayoutBinding toastLayoutBinding;
private View toastRootView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.activity_main);
    //activity_main.xml을 추상화한 클래스 얻기
    binding= ActivityMainBinding.inflate(getLayoutInflater());
    toastLayoutBinding = toastLayoutBinding.inflate(getLayoutInflater());

    //최상위 레이아웃(루트 뷰 ! 여기선 LinearLayout 요거 통째로 가져오는 것)을 얻기
    View rootview = binding.getRoot();
    toastRootView=toastLayoutBinding.getRoot();
    //레이아웃 전개
    setContentView(rootview);
    //binding객체로 뷰에 직접 접근
    //리스너 부착
    binding.btnShort.setOnClickListener(handler);
    binding.btnLong.setOnClickListener(handler);
    binding.btnCustom.setOnClickListener(handler);
}////
//이벤트 처리하기(익명클래스로)
private View.OnClickListener handler = view ->{
    String msg = binding.infoMessage.getText().toString();
  if(view.getId()==R.id.btnShort){
      Toast.makeText(view.getContext(), msg, Toast.LENGTH_SHORT).show();
  }
  else if(view.getId()==R.id.btnLong){
      Toast.makeText(view.getContext(), msg, Toast.LENGTH_LONG).show();
  }
  else{
      //사용자 입력값을 토스트용 커스텀뷰의 덱스트뷰에설정
      toastLayoutBinding.textView.setText(msg);
      Toast toast = new Toast(view.getContext());
      //토스트 지속시간설정
      toast.setDuration(Toast.LENGTH_LONG);
      //토스트의 화면전개
      toast.setView(toastRootView);
      //토스트보이기!!!
      toast.show();
  }
};

 

 

토스트용 커스텀 뷰 설정

toast_layout.xml

 

<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="wrap_content"
    android:gravity="center_horizontal"
    android:padding="10dp"
    android:background="@drawable/layout_rounded"
    >
    <ImageView
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"
        android:src="@drawable/icon2"
        android:scaleType="fitXY"
        />
    <TextView
        android:layout_width="0dp"
        android:layout_weight="8"
        android:layout_height="50dp"
        android:id="@+id/textView"
        android:gravity="center"
        android:textColor="@color/white"
        android:textSize="18sp"
        android:maxLines="1"
        android:ellipsize="end"

        />
    <!--
            ... 표시하기
            android:singleLine="true" dprecated됨
            android:maxLines="1" :한 줄만 표시
            ellipsize:Text가 TextView를 넘어갔을 때 표시할 방법을 설정
            ellipsize = "end" - 뒷 부분을 ...으로 표시
            아래는 maxLines와 함께쓰면 빨간줄 :tools:ignore="EllipsizeMaxLines" 추가 시 제거됨
            ellipsize = "none" - ... 없이 뒷 부분 잘라서 표시 (기본)
            ellipsize = "start" - 앞 부분을 ...으로 표시
            ellipsize = "middle" - 중간 부분을 ...으로 표시
            ellipsize = "marquee" - 흐르는 텍스트 효과
            아래 세줄과 자바코드에서 textView.setSelected(true)추가하면 marquee가 적용 됨
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:singleLine="true"
   -->
</LinearLayout>

 

잘나옴

 



위젯을 배우자

activity_main.xml

버튼의 색상을 #ffffffff등 색생코드로 지정하려면
매니페스트파일의 theme속성을 Theme.AppCompat계열로
바꿔라
예:android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar"


<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF00FF00"
        android:text="기본 버튼"/>
    <!-- android:enabled="false"시 디폴트 버튼이 표시된다-->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="셀렉터 버튼(이미지)"
        android:background="@drawable/button_image_selector"

        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_color_selector"
        android:text="셀렉터 버튼(색상)"/>
    <!--입력한 문자열의 길이 출력을 하기위한 텍스트뷰-->
    <!-- 시스템에서 제공하는 기본 에디트 텍스트-->
    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="20dp"
        android:background="#8BC34A"
        android:text="여기에 문자열 길이 표시" />

    <EditText
        android:id="@+id/basicEditText"
        android:hint="기본 에디트 텍스트"
        android:textColorHint="#00ff00"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <!--내가 만든 커스텀 EditText-->
    <!-- 아래 주석처리후 자바코드에서 직접 new로 생성-->

    <com.kosmo.customview10_3.view.MyEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/myEditText"
        android:hint="내가 만든 에디트 텍스트"
        android:textColorHint="#FF0000"
        />
</LinearLayout>

여러 res 사용할거 

drawable 폴더에 이미지 등 넣어놓기

 

 

MainActivity.java

제어하기 

public class MainActivity extends AppCompatActivity {

    //기본 에디트 텍스트상자로 문자열길이 표시 구현용
    private int textLength;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //위젯 얻기
        TextView textView = findViewById(R.id.textview);
        EditText editText = findViewById(R.id.basicEditText);
        LinearLayout layout = findViewById(R.id.linearlayout);

        //1]내가 만든 EditText를 자바코드로 부착하는 경우
        //MyEditText myEditText= new MyEditText(this);
        //myEditText.setHint("내가 만든 에디트 텍스트");
        //myEditText.setHintTextColor(Color.RED);
        //myEditText.setOnTextLengthListener(txtLength->textView.setText(String.valueOf(txtLength)));
        //레이아웃(루트 뷰)에 부착 :addView(View view)
        //layout.addView(myEditText);
        //2]xml에 내가 만든 EditText를 태그로 등록한 경우
        MyEditText myEditText=findViewById(R.id.myEditText);
        myEditText.setOnTextLengthListener(txtLength->textView.setText(String.valueOf(txtLength)));

        editText.addTextChangedListener(new TextWatcher() {
            //한글자 입력전 혹은 삭제전마다 호출됨
            @Override
            public void beforeTextChanged(CharSequence text, int start, int count, int after) {
                Log.i("com.kosmo.customview","기본 에디트텍스트:[beforeTextChanged]");
            }
            //한글자 입력시 혹은 삭제시마다 호출됨
            @Override
            public void onTextChanged(CharSequence text, int start, int before, int count) {
                /*
                text:에디트 텍스트에 입력된 문자열
                start:새로 추가되거나 삭제된 문자열의 시작 인덱스
                before:삭제된 문자열의 갯수
                count:새로 추가된 문자열의 갯수
                 */
                textLength+=count-before;
                textView.setText(String.valueOf(textLength));
                Log.i("com.kosmo.customview","기본 에디트텍스트:[onTextChanged]");
                Log.i("com.kosmo.customview",String.format("text:%s,start:%s,before:%s,count:%s",text,start,before,count));
            }
            //한글자 입력후 혹은 삭제후마다 호출됨
            @Override
            public void afterTextChanged(Editable editable) {
                Log.i("com.kosmo.customview","기본 에디트텍스트:[afterTextChanged]");
            }
        });

    }///////////////

 

 

'학원 > ANDROID' 카테고리의 다른 글

01/06 78-3[Android] compoundbutton  (1) 2023.01.07
01/06 78-2[Android] clockpicker  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07
01/05 77-3 [Android] STYLE&THEME  (0) 2023.01.07
01/05 77-2 [Android] GridLayout /LayoutExam  (1) 2023.01.07

resource


테그이름이 리소스 종류
ImageView 이미지 표시할 때 사용하는 위젯
이미지파일은 drawable폴더에 넣어놓음

 

**res디렉토리
   drawable - 이미지,xml파일
   values-문자열,배열,색상,크기등을 정의한 xml파일 ==> 파일명이 정해져 있다
   

[레이아웃용 xml(activity_main.xml)에서 res폴더에 있는 리소스 참조 시]
-->ees 폴더에 있는자원들은layout에서도 자바코드에서도 사용이 가능하다는 것! 
1.drawable디렉토리

         @drawale/이미지파일명

2.values디렉토리
          문자열-@string/name속성값
          색상-@color/name속성값
          크기-@dimen/name속성값

 

 [자바소스에서 참조시]
     Resources resource = getResources();
 1. drawable디렉토리:
   resource.getDrawable(R.drawable시작하는 리소스아이디)
 2. values디렉토리:
   문자열-resource.getString(R.string시작하는 리소스 아이디)
   색상-resource.getColor() 혹은 ContextCompat.getColor(Context,R.color시작하는 리소스아이디)
   크기-resource.getDimension(R.dimen시작하는 리소스아이디)

    cannot resolve symbol~ 해결법(오류 해결)
    1. Build메뉴
       Clean project->Rebuild Project
    2. File 메뉴
       Sync Project with Gradle Files
    3. File 메뉴
       Invalidate Cache/Restart

 

 

테스트하기 위해 res폴더에 리소스 자원들을 가져다 놔야함

 

1. xml파일에서 리소스 참조  activity_main.xml  

<!-- res폴더의 리소스를 xml속성값으로 설정-->
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/xmlMessage"
    android:textSize="@dimen/xmlDimen"
    android:textColor="@color/xmlColor"/>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/picture_emergency"/>

<!--밑에는 res폴더의 리소스를 자바코드로 적용-->
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/codeTextview"
    />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/codeImageview"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/codeButton"
    android:text="@string/buttonText"/>

 

2.자바코드에서 참고 

MainActivity.java

아 여기서도 자바에서의 콘솔창처럼 값을 읽어 올 수 있는데

Log.i( )로 읽어온다!

확인은 하단에 Logcat 으로 가능하고 필터로 태그걸어서 한 번 걸러주는게 좋음

태그 거는건 요렇게 설정

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //위젯열기
    TextView textView = findViewById(R.id.codeTextview);
    ImageView imageView = findViewById(R.id.codeImageview);
    Button button=findViewById(R.id.codeButton);
    //values폴더의 string.xml과 drawable폴더에 있는 이미지 접근 시
    //getStrig()이나 getDrawable()로 직접 접근 가능! -Resources객체 불필요!!
    //왜냐면 앱에서 가장 많이 사용하는 리소스이기 때문에 편하게 쓰라고 제공 해 주나 봄
    Log.i("com.kosmo.resource",String.format("문자열 데이터:%s",getString(R.string.codeMessage)));


    //1.res폴더에 정의된 모든 리소스를
    // 얻어올 수 있는 클래스 :  Resources -getResources(); 메소드로 얻는다
    Resources resources= getResources();

    //텍스트뷰의 text속성 설정
    textView.setText(R.string.codeMessage);
    //textView.setText(getString(R.string.codeMessage));
    //textView.setTextSize(20);//기본 단위가 SP
    //textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);//위와 동일
    //textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,resources.getDimension(R.dimen.xmlDimen));
    /*
        GETdIMENSION()이 문제여////  이 메소드가 pixel형태로 리턴
    ※ getDimension() 메소드가 pixel 형태로 리턴한다
      dimens.xml에 sp라고 명시시
      getDimension () 은 알아서 pixel로 변환해서 리턴
      dimens.xml에서 sp로 설정한 값을 자바코드로 적용시 아래 코드로 읽어와야
      크기가 똑같이 적용됨 즉 숫자로 직접 지정했을때와 같다
      */
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,resources.getDimension(R.dimen.xmlDimen));
   // textView.setTextColor(resources.getColor(R.color.xmlColor));
    textView.setTextColor(ContextCompat.getColor(this,R.color.xmlColor));

    //이미지뷰의 src속성 설정
    //방법1. imageView객체.setImageResource(int 리소스아이디)
    //imageView.setImageResource(R.drawable.picture_emergency);
    //방법2.ImageView객체.setImageDrawable(Drawable)
    //imageView.setImageDrawable(getDrawable(R.drawable.picture_emergency));
    //방법3 ImageView객체.setImageBitmap(Bitmap)
    //Bitmap bitmap=((BitmapDrawable)getDrawable(R.drawable.picture_emergency)).getBitmap();
    //BitmapFactory.decodeResource(Resources객체,리소스 아이디)

    Bitmap bitmap=BitmapFactory.decodeResource(resources,R.drawable.picture_emergency);
    imageView.setImageBitmap(bitmap);

    button.setOnClickListener(v ->{
        int[] ages=resources.getIntArray(R.array.ages); //int-array 는 없음
        String[] mountains=resources.getStringArray(R.array.mountains);
        Log.i("com.kosmo.resource","나이대:"+ Arrays.toString(ages));
        Log.i("com.kosmo.resource","산:"+ Arrays.toString(mountains));
    });

}

log에출력도 잘 됨!

'학원 > ANDROID' 카테고리의 다른 글

01/06 78-2[Android] clockpicker  (1) 2023.01.07
01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-3 [Android] STYLE&THEME  (0) 2023.01.07
01/05 77-2 [Android] GridLayout /LayoutExam  (1) 2023.01.07
01/05 77-1 [Android] FrameLayout  (1) 2023.01.07

[STYLE&THEME]
   css같은거

 

THEME
   테마 - 스타일을 모아서 전체  에 적용

themes.xml 에가서 기본 테마 값들을 변경할 수도 있고 내가 커스텀해서 변경 할 수도 있음  

(여기서는 값만 세팅하고

 manifestes > AndroidManifest.xml 요기랑 MainActivity.java 에서 적용하는 것 같음)

 [디폴트 - 기본 메인적용& 액션바 없애기]

 

1.xml파일설정

 

1-1.themes.xml

<style name="Theme.StyleTheme08" parent="Theme.MaterialComponents.DayNight.NoActionBar">

1-2.AndroidManifest.xml

android:theme="@style/Theme.MaterialComponents.NoActionBar"

2.자바코드로 없애기

getSupportActionBar().hide();
setContentView(R.layout.activity_main);

 

[내가만든 테마 적용하기]

themes.xml에 내가만든 스타일을테마로 적용 (자바코드로)
setTheme()
내가 만든 리소스는 R.java(R클래스)에 자동으로 등록됨
내가만든 자원은 R.리소스종류로 접근한다.

(cf.안드로이드에서 제공하는 리소스 사용 시는
     자바코드: android.R시작 레이아웃용

     xml:@android로 시작)

 

 

themes.xml

<!-- Customize your theme here. -->
<style name="Theme.MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
   <!--글자색은 흰색-->
    <item name="android:textColor">#ffffff</item>
    <!--배경색-->
    <item name="android:background">#E8C45A</item>
    <!--글자크기-->
    <item name="android:textSize">18sp</item>
</style>

<!--위의 내가 만든 스타일 상속  =>요거도 가능하네-->
<style name="Theme.MyThemeChild" parent="Theme.MyTheme">
    <!--글자크기 오버라이딩-->
    <item name="android:textSize">25sp</item>
    <!--패딩-->
    <item name="android:paddingBottom">40dp</item>
</style>

 

AndroidManifest.xml

android:theme="@style/Theme.MyTheme"

 

MainActivity.java

 setTheme(R.style.Theme_MyThemeChild);   //자바코드가 우선이라서 다 무시되고 이게 적용 됨 !

[STYLE]

 스타일 - 특정 위젯/뷰

스타일 적용 순위
위젯의 스타일 > 앱의 테마
 즉 android:textColor를 위젯과 앱의 테마에 동시 지정 시
 젯에 지정한 스타일이 우선한다

   [ 안드로이드에서 제공하는 스타일을 위젯에 적용]

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp"
    android:text="텍스트 스타일(색상 및 크기 등 미지정)"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView"
    style="@style/TextAppearance.AppCompat.Headline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="34dp"
    android:text="안드로이드 제공 스타일:스타일 적용"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.703"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

 

[내가 만든 스타일을 위젯에 적용]

테마가 MaterialComponents일때 버튼은 백그라운드가 적용이 안된다.
즉MaterialComponents테마는
button자체적으로 별도의 background가 적용되어 있어서 바꿀 수 없다
아래 두 가지 설정으로 배경색을 설정 할 수 있있다
         backgroundTint로 색상 설정
         backgroundTintMode로 add 설정

 

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="44dp"
    android:backgroundTint="@color/my_button_color"
    android:backgroundTintMode="add"
    android:text="테마적용(텍스트 색상 및 크기)"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

'학원 > ANDROID' 카테고리의 다른 글

01/06 78-1 [Android] Costomview  (1) 2023.01.07
01/05 77-4 [Android] resource  (0) 2023.01.07
01/05 77-2 [Android] GridLayout /LayoutExam  (1) 2023.01.07
01/05 77-1 [Android] FrameLayout  (1) 2023.01.07
01/04 76-4 [Android] TableLayout  (0) 2023.01.04

[GridLayout]


FrameLayout보다 쉽고 사용하기 좋다고 함


<GridLayout>에 적용하는 속성
-rowCount: 행 개수

-columnCount :열 개수
-orientation:그리드를 수평방향으로 먼저 채울지 ,
                  수직방향으로 먼저 채울지 지정

ex.
수평이면  1 2 3
                 4 5 6
수직이면 1 3 5
               2 4 6

 

행 병합 할 때  요놈들 gravity랑 쌍으로 써야 제대로 병합됨!!
-layoput_rowSpan : 행을 지정된 개수 만큼 병합
-layout_columnSApan : 열을 지정된 개수 만큼 병합.
-layout_gravity:  병합 할 때 요놈을 꼭 같이 사용하자!!!

 

여긴 레이아웃위주로 보는거라 자바코드로 제어하는 건 없음!

 

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ca8787"
    android:rowCount="2"
    android:columnCount="2"
    android:orientation="horizontal"
    >
    <!--2x2로 정해 있어서 다 채우는게 가능함-->
    <Button android:text="1행1열"/>
    <Button android:text="1행2열" android:layout_width="match_parent"/>
    <Button android:text="2행1열"/>
    <Button android:text="2행2열" android:layout_gravity="fill_horizontal"/>

</GridLayout>


<GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#92b7e4"
    android:rowCount="2"
    android:columnCount="2"
    android:orientation="vertical"
    >
    <!-- android:layout_gravity="fill_vertical|fill_horizontal"  이게 걍 fill 임-->
    <Button android:text="1행1열" android:layout_width="150dp" android:layout_height="100dp"/>
    <Button android:text="2행1열"  android:layout_gravity="fill_horizontal"/>
    <Button android:text="1행2열" android:layout_gravity="fill_vertical|fill_horizontal"/>
    <Button android:text="2행2열" android:layout_width="match_parent" />
</GridLayout>


 

<!--병합하기-->
<GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ea96df"
    android:rowCount="3"
    android:columnCount="3"
    >
    <!---layoput_rowSpan
        -layout_columnSApan는
            -layout_gravity 와 같이쓰자-->
    <Button android:text="1행1열" android:layout_width="150dp" android:layout_height="100dp"/>
    <Button android:text="1행2열" android:layout_columnSpan="2" android:layout_gravity="fill"/>
    <Button android:text="2행2열" android:layout_rowSpan="2" android:layout_gravity="fill"/>
    <Button android:text="2행2열"/>
    <Button android:text="2행3열" android:layout_gravity="fill"/>
    <Button android:text="3행2열"/>
    <Button android:text="3행3열"  android:layout_gravity="fill"/>
</GridLayout>


 <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#add184"
        android:rowCount="3"
        android:columnCount="5"
        android:padding="10dp"
        >
        <TextView android:text="아 이 디 " android:layout_width="100dp" android:textSize="16sp" android:layout_gravity="fill_horizontal" android:gravity="center"/>
        <EditText android:hint="아이디를 입력하세요" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal"/>
        <TextView android:text="비 밀 번 호 " android:layout_width="100dp" android:textSize="16sp" android:gravity="center"/>
        <EditText android:hint="비밀번호를 입력하세요" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:inputType="textPassword"/>
        <Button android:text="확인" android:layout_row="2" android:layout_column="3"/>
        <Button android:text="취소" />

    </GridLayout>

</androidx.appcompat.widget.LinearLayoutCompat>

 


연습하기

 

[리니어 레이아웃]

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:textSize="20sp"
        android:textColor="#E38989"
        android:text="리니어 레이아웃"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--리니어 레이아웃 작성-->
        <androidx.appcompat.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#E38989"
            >
        <androidx.appcompat.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            >
           <TextView
               android:layout_width="100dp"
               android:layout_height="match_parent"
               android:text="아 이 디"
               android:textSize="20sp"
               android:gravity="center"/>
            <androidx.appcompat.widget.AppCompatEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="아이디를 입력하세요"
                android:textSize="15sp"
                android:gravity="center" />

            </androidx.appcompat.widget.LinearLayoutCompat>

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                >
                <TextView
                    android:layout_width="100dp"
                    android:layout_height="match_parent"
                    android:text="비 밀 번 호"
                    android:textSize="20sp"
                    android:gravity="center"
                    >
                </TextView>
                <androidx.appcompat.widget.AppCompatEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="비밀번호를 입력하세요"
                    android:textSize="15sp"
                    android:gravity="center"
                    >
                </androidx.appcompat.widget.AppCompatEditText>
            </androidx.appcompat.widget.LinearLayoutCompat>
            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="right"
                >
                <Button
                  android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="확인"
                    android:layout_gravity="end"/>
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="취소"
                    android:layout_marginRight="10dp"
                    android:layout_marginLeft="5dp"
                    />

            </androidx.appcompat.widget.LinearLayoutCompat>
        </androidx.appcompat.widget.LinearLayoutCompat>
    </ScrollView>
</LinearLayout>


[테이블레이아웃]

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:textSize="20sp"
        android:textColor="#E38989"
        android:text="테이블 레이아웃"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#E8B09F"
        >
        <!--테이블 레이아웃 작성-->
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchColumns="*"
            android:padding="10dp"
            >
            <TableRow>
                <TextView android:gravity="center" android:layout_height="match_parent" android:textSize="18sp" android:text="아 이 디" android:layout_span="3" />
                <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/username"
                    android:hint="아이디를 입력하세요"
                    android:layout_span="4"
                    android:gravity="center"/>
            </TableRow>
            <TableRow>
                <TextView android:gravity="center" android:layout_height="match_parent" android:textSize="18sp" android:text="비 밀 번 호" android:layout_span="3"/>
                <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/password"
                    android:hint="비밀번호를 입력하세요"
                    android:inputType="textPassword"
                    android:layout_span="4"
                    android:gravity="center"/>
            </TableRow>
            <TableRow>
                <Button android:text="확인"   android:id="@+id/btnOk" android:layout_column="5"/>
                <Button android:layout_marginLeft="5dp"  android:id="@+id/btnCancel" android:text="취소" />
            </TableRow>
        </TableLayout>
    </ScrollView>
</LinearLayout>


 

[그리드 레이아웃]

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:textSize="20sp"
        android:textColor="#E38989"
        android:text="그리드 레이아웃"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--그리드 레이아웃 작성-->
        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#add184"
            android:rowCount="3"
            android:columnCount="5"
            android:padding="10dp"
            >
            <TextView android:text="아 이 디 " android:layout_width="100dp" android:textSize="16sp" android:layout_gravity="fill_horizontal" android:gravity="center"/>
            <EditText android:hint="아이디를 입력하세요" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal"/>
            <TextView android:text="비 밀 번 호 " android:layout_width="100dp" android:textSize="16sp" android:gravity="center"/>
            <EditText android:hint="비밀번호를 입력하세요" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:inputType="textPassword"/>
            <Button android:text="확인" android:layout_row="2" android:layout_column="3"/>
            <Button android:text="취소" android:layout_marginLeft="5dp"/>

        </GridLayout>
    </ScrollView>
</LinearLayout>


 

[상대적 레이아웃]

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textColor="#E38989"
        android:text="상대적 레이아웃"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--상대적 레이아웃 작성-->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#AFF0F8">

            <TextView
                android:id="@+id/user"
                android:layout_width="100dp"
                android:layout_height="42dp"
                android:gravity="center"
                android:text="아 이 디"
                android:textSize="20sp"
                />
            <androidx.appcompat.widget.AppCompatEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/user"
                android:hint="아이디를 입력하세요"
                android:gravity="center"
                android:textSize="15sp"
                android:id="@+id/userEdit"
                />
                <TextView
                android:layout_width="100dp"
                android:layout_height="42dp"
                android:gravity="center"
                android:text="비 밀 번 호"
                android:textSize="20sp"
                android:layout_below="@id/user"
                android:layout_alignLeft="@id/user"
                android:id="@+id/pass"
                />
            <androidx.appcompat.widget.AppCompatEditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="비밀번호호 입력하세요"
                android:gravity="center"
                android:layout_below="@id/userEdit"
                android:layout_alignRight="@id/userEdit"
                android:id="@+id/passEdit"
                android:layout_toLeftOf="@id/pass"
                android:layout_toRightOf="@id/pass"
                />
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="취소"
                    android:layout_below="@id/passEdit"
                    android:layout_alignRight="@id/passEdit"
                    android:id="@+id/cancel"
                android:layout_marginRight="10dp"
                 />
            <Button
                android:layout_marginRight="5dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="확인"
                android:layout_toLeftOf="@id/cancel"
                android:layout_below="@id/passEdit"
                />
        </RelativeLayout>
    </ScrollView>
</LinearLayout>
</LinearLayout>

'학원 > ANDROID' 카테고리의 다른 글

01/05 77-4 [Android] resource  (0) 2023.01.07
01/05 77-3 [Android] STYLE&THEME  (0) 2023.01.07
01/05 77-1 [Android] FrameLayout  (1) 2023.01.07
01/04 76-4 [Android] TableLayout  (0) 2023.01.04
01/04 76-3 [Android] RelativeLayout  (0) 2023.01.04

안드로이드.... 재밌는데

팀플하느라 복습 거의못하고 있음

아쉽....주말에라도 몰아서 정리 해 놔야지...

 

[FrameLayout]

 

원래는 1개의 화면은 1개의 activity로 구성이 되는데  
1개의activity 에 여러 개 의 화면을 띄우고 싶을 때 사용한다. (사실은  아래서 위로 쌓이는 것임)

 

둘째날 부터 도구프로그램에 조금 씩 적응해 가는 것 같음!!!

activity_main.xml 에서는 진짜 화면구성하는 공간인거 같고 ! 스프링에서 뷰 단 같은 느낌?
MainActivity.java 에서는 자바코드로 이벤트 입히기!! 요기가 컨트롤러나 서비스 같은 곳 같다!

 

activity_main(뷰단)부터 구성 상단에 버튼 세 개를 배치할 거

 <!--상단 메뉴 배치-->
<androidx.appcompat.widget.LinearLayoutCompat
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <!-- Material은 버튼의 background속성이 무시된다
        background적용하기 위해서는 테마를 바꾸자
        Theme.AppCompat.Light 로(res->values->themes->themes.xml)-->

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="메뉴1"
        android:id="@+id/btnMenu1"
        android:background="@color/black"
        android:textColor="@color/white"
        />
    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="메뉴2"
        android:id="@+id/btnMenu2"
        android:background="@color/black"
        android:textColor="@color/white"
        android:layout_marginLeft="1dp"
        android:layout_marginRight="1dp"
        />
    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="메뉴3"
        android:id="@+id/btnMenu3"
        android:background="@color/black"
        android:textColor="@color/white"
        />
</androidx.appcompat.widget.LinearLayoutCompat>

 

저렇게 id를 준거는 MainActivity.java 로가서 자바코드로 제어를하기 위한 연결고리라고 생각하면 된다

그리고 배경색 이나 글자색에도 @요게 보이는데 @에 붙어있는 것을 

참조하겠다는 표시라고 보면 이해하기 쉽다!

 

화면구성 : 버튼메뉴에 따른 화면구성 프레임 아웃 배치

첫 번째 화면

프레임레이아웃으로 세번째까지 크게 감싸는거
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    >

    <!--1 화면-->
    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/frame1"
        android:background="#D69292"
        android:padding="10dp"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="첫번째 화면입니다"
            android:textSize="20sp"
            android:gravity="center_horizontal"/>
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchColumns="*"
            android:padding="10dp"
            >
            <TableRow>
                <TextView android:text="아  이  디" android:layout_height="match_parent" android:gravity="center_vertical" android:textSize="18sp" />
                <EditText android:id="@+id/user"  android:hint="아이디를 입력하세요" android:layout_span="8"/>
            </TableRow>
            <TableRow>
                <TextView android:text="비 밀 번 호" android:layout_height="match_parent" android:gravity="center_vertical" android:textSize="18sp"/>
                <EditText android:id="@+id/pass" android:hint="비밀번호를 입력하세요" android:inputType="textPassword" android:layout_span="8"/>
            </TableRow>
            <TableRow>
                <Button android:id="@+id/btnOk" android:text="확인" android:layout_column="7"/>
                <Button android:id="@+id/btnCancel" android:text="취소" android:layout_marginLeft="5dp"/>
            </TableRow>
        </TableLayout>
    </androidx.appcompat.widget.LinearLayoutCompat>

 

두 번째 화면 

<!--2 화면-->
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/frame2"
    android:background="#A8e6ab"
    >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="두 번째 화면 입니다."
        android:layout_centerInParent="true"
        />
 </RelativeLayout>

 

세 번째 화면 

<!--3 화면-->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/frame3"
            android:background="#81a2e3"

            >
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="세 번째 화면 입니다."
                android:layout_centerInParent="true"
                />
        </RelativeLayout>
    </FrameLayout>

</androidx.appcompat.widget.LinearLayoutCompat>

 

이제 자바코드로 제어 하러 감 MainActivity.java자바스크립트에서 이벤트거는거와 비슷하다크게보면1.위젯 얻기 (=이벤트객체 얻기)

2.리스너 부착(=이벤트 걸기) 

요렇게함!

이벤트 거는 방법은 2가지로 정리할 거

 

public class MainActivity extends AppCompatActivity {

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

        //위젯얻기
        Button btnMenu1 = findViewById(R.id.btnMenu1);
        Button btnMenu2 = findViewById(R.id.btnMenu2);
        Button btnMenu3 = findViewById(R.id.btnMenu3);

        FrameLayout container = findViewById(R.id.container);
        LinearLayoutCompat frame1= findViewById(R.id.frame1);
        RelativeLayout frame2= findViewById(R.id.frame2);
        RelativeLayout frame3= findViewById(R.id.frame3);

 

방법1.: 뷰의 visiviltity 속성  android:visibility="invisible"  (화면 보이기/안보이기)

 //리스너 부착
    btnMenu1.setOnClickListener(v->{           
       if(frame1.getVisibility()== View.INVISIBLE){
            frame1.setVisibility(View.VISIBLE);
        }
    frame2.setVisibility(View.INVISIBLE);
    frame3.setVisibility(View.INVISIBLE);
    });
    
    btnMenu3.setOnClickListener(v->{
      if(frame3.getVisibility()== View.INVISIBLE){
            frame3.setVisibility(View.VISIBLE);
      }
    frame1.setVisibility(View.INVISIBLE);
    frame2.setVisibility(View.INVISIBLE);
    });

 

방법2 : 레이아웃 메소드 이용 (클릭하면 모든 뷰 제거하고 클릭한 화면면 뷰를 부착하는 원리)

    //부착된 모든 뷰 제거
    container.removeAllViews();
    //첫 번째 화면 부착
    container.addView(frame1);

    //리스너 부착
    btnMenu1.setOnClickListener(v->{
        container.removeAllViews();
        container.addView(frame1);
    });
    btnMenu2.setOnClickListener(v->{
        container.removeAllViews();
        container.addView(frame2);
    });
    btnMenu3.setOnClickListener(v->{
        container.removeAllViews();
        container.addView(frame3);
    });
}
}

 

안드로이드 하면서 람다식을 드디어! 제대로 사용 해 보는 것 같음

이해가 안됐는데

계속 써보니

꽤 간편하고 좋은 것 같다 !!

 

 

'학원 > ANDROID' 카테고리의 다른 글

01/05 77-3 [Android] STYLE&THEME  (0) 2023.01.07
01/05 77-2 [Android] GridLayout /LayoutExam  (1) 2023.01.07
01/04 76-4 [Android] TableLayout  (0) 2023.01.04
01/04 76-3 [Android] RelativeLayout  (0) 2023.01.04
01/04 76-2 [Android] LinearLayout  (1) 2023.01.04

TableLayout

태이블 배치

요건 걍 보고 이해하는걸 위주로....

 

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="#E4BF4E"
    >
    <TableRow>
        <Button android:text="1행1열" />
        <Button android:text="1행2열" />
        <Button android:text="1행3열" android:layout_width="200dp"/>
    </TableRow>
    <TableRow>
        <Button android:text="2행1열" android:layout_height="70dp"/>
        <Button android:text="2행2열" android:layout_height="match_parent"/>
        <Button android:text="2행3열" android:layout_height="match_parent" /> <!--위에 200dp가 같이 적용된 것-->
    </TableRow>
    <TableRow>
        <Button android:text="3행1열" android:layout_height="match_parent" />
        <Button android:text="3행2열" android:layout_height="80dp"/>
    </TableRow>
</TableLayout>

 

stretchColumns 적용

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#bb9cf3"
    android:stretchColumns="*"
    >
    <!--stretchColumns 에 *는 모든 컬럼이 동일한 비율로 strech된다
    -->
    <TableRow>
        <Button android:text="1행1열" />
        <Button android:text="1행2열" />
        <Button android:text="1행3열" />
    </TableRow>
    <TableRow>
        <Button android:text="2행1열" />
        <Button android:text="2행2열" />
    </TableRow>
</TableLayout>

 

html에서 했던 

표합치기 기능이랑 비슷하다고 생각하면 됨 !!

 

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#DF58F6"
    android:stretchColumns="1,2"
    >
    <!---2번 째, 3번째  컬럼이 동일한 비율로 strech-->
    <TableRow>
        <Button android:text="1행1열" />
        <Button android:text="1행2열" />
        <Button android:text="1행3열" />
    </TableRow>
    <TableRow>
        <Button android:text="2행1열" />
        <Button android:text="2행2열" />
    </TableRow>
</TableLayout>

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#61CAC0"
    android:stretchColumns="3"
    >
    <!--병합(layout_span): 해당 컬럼을 포함 한 컬럼 수-->
    <TableRow>
        <Button android:text="1행1열" />
        <Button android:text="1행2열" />
        <Button android:text="1행3열" android:layout_span="2"/>
    </TableRow>
    <TableRow>
        <Button android:text="2행1열" />
        <Button android:text="2행2열" />
        <Button android:text="2행3열" />
        <Button android:text="2행4열" />
    </TableRow>
</TableLayout>

 

 

 

왼쪽이 비었을 때 오른쪽으로 표들을 밀어버리고 싶으면??

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#BCAE38"
    android:stretchColumns="*"
    >
    <!--컬럼을 밀어요-->
    <TableRow>
        <Button android:text="1행1열" />
        <Button android:text="1행2열" />
        <Button android:text="1행3열" />
        <Button android:text="1행4열" />
    </TableRow>
    <TableRow>
        <Button android:text="2행3열" android:layout_column="2"/>
        <Button android:text="2행4열" />
    </TableRow>
</TableLayout>

 

 

>>> 최종보스  로그인 폼 만들기

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="*"
    android:padding="10dp"
    >
    <TableRow>
        <TextView android:gravity="center" android:layout_height="match_parent" android:textSize="18sp" android:text="아 이 디" android:layout_span="3" />
        <androidx.appcompat.widget.AppCompatEditText
            android:hint="아이디를 입력하세요"
            android:layout_span="4"
            android:gravity="center"
            />
    </TableRow>
    <TableRow>
        <TextView android:gravity="center" android:layout_height="match_parent" android:textSize="18sp" android:text="비 밀 번 호" android:layout_span="3"/>
        <androidx.appcompat.widget.AppCompatEditText
            android:hint="비밀번호를 입력하세요"
            android:inputType="textPassword"
            android:layout_span="4"
            android:gravity="center"/>
    </TableRow>
    <TableRow>
        <Button android:text="확인" android:layout_column="5"/>
        <Button android:layout_marginLeft="5dp" android:text="취소" />
    </TableRow>
</TableLayout>
</ScrollView>

RelativeLayout

내부에 포함 된 위젯들을 상대적인 위치로 배치
다른 위젯의 상대위치에 관련된 속성이다.
상대적 레이아웃 미정 시 항상 left, top이 기본

아..너무 헷깔려.. 공간지각능력이 부족한 나는 배치가 너무 힘드렁

*** 배치를 위해서 아이디 속성도 추가할 수 있다 !!


우선 전체 크게 감싼 태그(걍 나중 참고용 )

<androidx.appcompat.widget.LinearLayoutCompat
    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">
    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#888800"
        >
      
      여기다가 코드 작성 
     
     </androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#C69B5B">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="왼쪽 위" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="위쪽수평중앙"
            android:layout_centerHorizontal="true"
            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="위쪽오른쪽"
            android:layout_alignParentRight="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="왼쪽 수직중앙"
            android:layout_centerVertical="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="정중앙"
            android:layout_centerInParent="true"
            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="오른쪽 수직중앙"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="왼쪽바닥"
            android:layout_alignParentBottom="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="가운데바닥"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="오른쪽바닥"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            />
 </RelativeLayout>



android:id="@+id/아이디명
요렇게 아이디 지정해서
하나의 기준으로 사용해도 가능함!

 <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#008888"
        >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#CF7777"
            >

            <Button
                android:id="@+id/base"
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:text="기준"
                android:textSize="40sp" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="가"
                android:layout_toLeftOf="@id/base"
                android:layout_alignTop="@id/base"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="나"
                android:layout_toLeftOf="@id/base"
                android:layout_alignBaseline="@id/base"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="다"
                android:layout_toLeftOf="@id/base"
                android:layout_alignBottom="@id/base"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="라"
                android:layout_above="@id/base"
                android:layout_alignRight="@id/base"
                android:id="@+id/la"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="마"
                android:layout_toRightOf="@id/la"
                android:layout_alignTop="@id/la"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="바"
                android:layout_toRightOf="@id/base"
                android:layout_alignTop="@id/base"
                android:id="@+id/ba"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="사"
                android:layout_below="@id/base"
                android:layout_alignLeft="@id/base"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="아"
                android:layout_below="@id/ba"
                android:layout_alignRight="@id/ba"
                />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="자"
                android:layout_toRightOf="@id/base"
                android:layout_alignBottom="@id/base"
                />
        </RelativeLayout>
    </androidx.appcompat.widget.LinearLayoutCompat>

+ Recent posts