안드로이드 프로그래밍[Kotiln Code]/안드로이드 부분 함수(권한얻기,인텐트, 데이터바인딩)

UI 관련 Tips and Trick

훈츠 2020. 4. 2. 16:04
반응형

안녕하세요. 훈츠 입니다. UI 관련 Tips and Trick 포스팅 합니다. 


1. Dependency 추가 

implementation "com.google.android.material:material:1.1.0"

2. Style 변경 

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

 

3. ConstraintLayout 

  • View 들의 위치 지정시 위처 정보의 네점은 parent로 두고, Vertical_bias 혹은 Horizontal_bias로 조정 합니다. 
  • View 의 위치를 자석으로 붙일때는 Top_toBottomOf 를 이용합니다. 
  • View 의 text size 지정시, textAppearance 를 이용 합니다. = Headline, Body, Display ...
  • View 의 xml 화면 에서 글씨를 미리 보려면, tools:text =" 이곳을 이용 합니다. "
  • DataBinding 시 
    • text 값 연결  : android:text='@{"Count value:" + viewModel.liveData.count }'
    • onClick 이벤트 연결 : android:onClick="@{ () -> viewmodel.onChangeRandomFruitClick() }"

 

 

<TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{viewmodel.currentRandomFruitName}"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.12"
            tools:text="Some random fruit"
/>
<Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:onClick="@{ () -> viewmodel.onChangeRandomFruitClick() }"
            android:text="Change Fruit"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView"
            app:layout_constraintVertical_bias="0.0"/>

 

반응형