Один из моих TextView - taking extra space
, хотя к нему не прикреплены какие-либо отступы или поля. Как вы видите на картинке ниже
XML-код TextView
<TextView
android:id = "@+id/txt_bundle_change_percentage"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "center_vertical"
android:alpha = "0.6"
android:fontFamily = "@font/suisse_intl_semi_bold"
android:text = "14.92%"
android:textColor = "@color/bundleScreenTextColor"
android:textSize = "@dimen/_12ssp" />
XML-файл макета, который содержит TextView
<LinearLayout
android:id = "@+id/bundle_change_percentage_layout"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"
android:gravity = "end"
android:orientation = "vertical">
<LinearLayout
android:id = "@+id/bundle_change_percentage_value_layout"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:orientation = "horizontal">
<ImageView
android:id = "@+id/txt_bundle_change_percentage_icon_up"
android:layout_width = "@dimen/_9sdp"
android:layout_height = "@dimen/_8sdp"
android:layout_gravity = "center_vertical"
android:alpha = "0.6"
android:src = "@drawable/ic_value_up"
android:tint = "@color/bundleScreenTextColor"
android:visibility = "visible" />
<ImageView
android:id = "@+id/txt_bundle_change_percentage_icon_down"
android:layout_width = "@dimen/_9sdp"
android:layout_height = "@dimen/_8sdp"
android:layout_gravity = "center_vertical"
android:alpha = "0.6"
android:scaleY = "-1"
android:src = "@drawable/ic_value_up"
android:tint = "@color/bundleScreenTextColor"
android:visibility = "visible" />
<TextView
android:id = "@+id/txt_bundle_change_percentage"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "center_vertical"
android:alpha = "0.6"
android:fontFamily = "@font/suisse_intl_semi_bold"
android:text = "14.92%"
android:textColor = "@color/bundleScreenTextColor"
android:textSize = "@dimen/_12ssp" />
</LinearLayout>
<TextView
android:id = "@+id/txt_bundle_change_percentage_heading"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:alpha = "0.6"
android:fontFamily = "@font/suisse_intl_regular"
android:text = "@string/txt_24h_price_change"
android:textColor = "@color/bundleScreenTextColor"
android:textSize = "@dimen/_9ssp" />
</LinearLayout>
просто используйте android: padding = "0dp", чтобы удалить отступы по умолчанию в текстовом представлении
setIncludeFontPadding (boolean includepad)
или в XML это будет:
android:includeFontPadding = "false"
Благодарность! это сработало, но все еще есть место. Можете ли вы придумать еще какое-нибудь решение?
Вы использовали собственный шрифт?
когда вам нужно ближе, добавьте это, чтобы выровнять текст по верхнему краю
textView.setGravity(Gravity.TOP);
Пожалуйста, обновите этот код. это будет работать.
<TextView
android:id = "@+id/txt_bundle_change_percentage"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:height = "24dp"
android:alpha = "0.6"
android:text = "14.92%"
android:textColor = "@color/colorAccent"
android:textSize = "24sp"
android:background = "@color/colorPrimary"
android:includeFontPadding = "false"
android:layout_marginTop = "-5dp"
android:layout_marginLeft = "-2dp"
/>
ваш шрифт может быть проблемой. Попробуйте использовать шрифт по умолчанию