<item name="android:height">,Changing android:layout_height and android:gravity in styles.xml

I'm new to android development and I've stumbled upon a problem I couldn't solve with the help of existing StackOverflow questions.

In the list of custom items I'm loading a TextView object which can use 2 different styles (both defined in styles.xml) - if there's a secondary TextView object, the style applied is itemHeadingText_Medium, and if not it's itemHeadingText_Large. I'm changing the style programmaticaly in the ListItemAdapter class.

bold

@android:color/black

100dp

center_vertical

bold

@android:color/black

Sadly, the android:layout_height and android:gravity aren't applied to the view, and whole app looks like that. Here's how both TextViews are defined:

android:id="@+id/heading"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@android:color/darker_gray"/>

android:id="@+id/secondary"

style="@style/itemSecondaryText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@android:color/holo_red_light"/>

I would like to center vertically the Lorem Ipsum heading of the second item provided in the screenshot.

EDIT: 25 June 2017

I managed to achieve what I wanted by changing the height programmatically using the getLayoutParams().height and adding the android:gravity attribute to the TextView xml definition - after all in both styles text can be centered vertically within its TextView.

Nevertheless, my question on how to do that in styles.xml is still open!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值