Skip to content

Commit

Permalink
#6 feat/홈 : 버튼 컴포넌트 수정
Browse files Browse the repository at this point in the history
- TextView 의 drawableStart 속성을 사용하는 경우, 아이콘 사이즈 변경이 어려워 이미지뷰로 대체
  • Loading branch information
HayleyKim0716 committed Aug 3, 2022
1 parent 78ec3be commit 5cfce75
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 4 additions & 4 deletions design/src/main/java/com/ftw/hometerview/design/Button.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ftw.hometerview.design
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.children
Expand All @@ -16,15 +17,14 @@ class Button @JvmOverloads constructor(
attributeSet: AttributeSet? = null,
defStyle: Int = 0
) : ConstraintLayout(context, attributeSet, defStyle) {
private val drawableStartImageView: ImageView
private val titleTextView: TextView
private val numberTextView: TextView

var icon: Drawable? = null
set(value) {
field = value
titleTextView.setCompoundDrawablesWithIntrinsicBounds(value, null, null, null)
titleTextView.compoundDrawablePadding =
resources.getDimensionPixelSize(R.dimen.button_drawable_padding)
drawableStartImageView.setImageDrawable(value)
}

var text: String? = null
Expand All @@ -46,6 +46,7 @@ class Button @JvmOverloads constructor(

init {
inflate(context, R.layout.view_button, this)
drawableStartImageView = findViewById(R.id.drawable_start_image_view)
titleTextView = findViewById(R.id.title_text_view)
numberTextView = findViewById(R.id.number_text_view)

Expand Down Expand Up @@ -81,5 +82,4 @@ class Button @JvmOverloads constructor(
super.setEnabled(enabled)
children.forEach { it.isEnabled = enabled }
}

}
23 changes: 19 additions & 4 deletions design/src/main/res/layout/view_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@
<merge 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:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"
>

<ImageView
android:id="@+id/drawable_start_image_view"
android:layout_width="@dimen/button_drawable_start_size"
android:layout_height="@dimen/button_drawable_start_size"
tools:src="@drawable/icon_like"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>

<TextView
android:id="@+id/title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/button_drawable_padding"
android:gravity="center_vertical"
android:fontFamily="@font/pretendard_regular"
android:textColor="@color/selector_button_color"
android:textSize="@dimen/button_text_size"
app:layout_constraintStart_toStartOf="parent"
android:textSize="12dp"
app:layout_constraintStart_toEndOf="@id/drawable_start_image_view"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="버튼"
/>

<TextView
Expand All @@ -27,6 +41,7 @@
android:textSize="@dimen/button_text_size"
app:layout_constraintStart_toEndOf="@id/title_text_view"
app:layout_constraintTop_toTopOf="parent"
tools:text="9"
/>

</merge>
2 changes: 2 additions & 0 deletions design/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<dimen name="button_text_size">12dp</dimen>

<dimen name="button_height">27dp</dimen>
<dimen name="button_drawable_start_size">14dp</dimen>
<dimen name="button_drawable_start_padding">4dp</dimen>
<dimen name="button_stroke_width">1dp</dimen>
<dimen name="button_radius">4dp</dimen>
<dimen name="button_horizontal_padding">8dp</dimen>
Expand Down

0 comments on commit 5cfce75

Please sign in to comment.