叠TextViews之间移除空间 [英] Remove space between stacked TextViews
问题描述
我有一个垂直的的LinearLayout
有两个的TextView
里面。前者包含一个静态文本属性(它的文字永远不会改变),最后包含一个倒退计时器。下图显示了两个项目:
我要消灭空白区域,这两个文本具有顶部和底部。我试了几种方法...
安卓includeFontPadding =假
机器人:lineSpacingMultiplier =1
机器人:lineSpacingExtra =0dp
机器人:paddingTop =0dp
机器人:paddingBottom会=0dp
机器人:layout_marginTop =0dp
机器人:layout_marginBottom =0dp
...但他们没有删除的文字上方的空间。我怎样才能使两种文本接近对方,没有任何额外的空间?
PS:我发现<一href="http://stackoverflow.com/questions/7162500/android-reduce-space-between-two-vertical-textviews">this类似的问题,但没有人回答了这个问题。
完整布局code:
&LT;的LinearLayout
机器人:ID =@ + ID / boxTime
机器人:方向=垂直
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:layout_centerHorizontal =真
机器人:layout_marginTop =20dp&GT;
&LT;的TextView
机器人:ID =@ + ID / textRemainingTime2
机器人:layout_width =WRAP_CONTENT
机器人:layout_heigh =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:重力=center_horizontal
机器人:TEXTSIZE =70sp
机器人:includeFontPadding =假
机器人:lineSpacingMultiplier =1
机器人:lineSpacingExtra =0dp
机器人:paddingTop =0dp
机器人:paddingBottom会=0dp
机器人:layout_marginTop =0dp
机器人:layout_marginBottom =0dp
机器人:文本=@字符串/标题/&GT;
&LT;的TextView
机器人:ID =@ + ID / textRemainingTime
机器人:layout_width =WRAP_CONTENT
机器人:layout_heigh =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:重力=center_horizontal
机器人:includeFontPadding =假
机器人:lineSpacingMultiplier =1
机器人:lineSpacingExtra =0dp
机器人:paddingTop =0dp
机器人:paddingBottom会=0dp
机器人:layout_marginTop =0dp
机器人:layout_marginBottom =0dp
机器人:TEXTSIZE =107sp
机器人:文本=@字符串/定时器/&GT;
&LT; / LinearLayout中&GT;
请文本等于TextView的底部基线。
公共类BaselineTextView扩展TextView的{
公共BaselineTextView(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
}
@覆盖
保护无效的OnDraw(帆布油画){
INT yOffset =的getHeight() - getBaseline均();
canvas.translate(0,yOffset);
super.onDraw(画布);
}
}
I have a vertical LinearLayout
with two TextView
inside it. The former contains a static text property (it's text never change) and the last contains a regressive timer. The image below shows both items:
I want to eliminate the blank space that both texts have both top and bottom. I've tried several approaches...
android:includeFontPadding="false"
android:lineSpacingMultiplier="1"
android:lineSpacingExtra="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
...but none of them removed the space above the text. How can I make both texts close to each other without any extra space?
PS: I've found this similar question, but no one answered it.
Full layout code:
<LinearLayout
android:id="@+id/boxTime"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" >
<TextView
android:id="@+id/textRemainingTime2"
android:layout_width="wrap_content"
android:layout_heigh="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:textSize="70sp"
android:includeFontPadding="false"
android:lineSpacingMultiplier="1"
android:lineSpacingExtra="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:text="@string/title" />
<TextView
android:id="@+id/textRemainingTime"
android:layout_width="wrap_content"
android:layout_heigh="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:lineSpacingMultiplier="1"
android:lineSpacingExtra="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:textSize="107sp"
android:text="@string/timer" />
</LinearLayout>
Make baseline of the text equal to the bottom of the TextView.
public class BaselineTextView extends TextView {
public BaselineTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
int yOffset = getHeight() - getBaseline();
canvas.translate(0, yOffset);
super.onDraw(canvas);
}
}
这篇关于叠TextViews之间移除空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!