[英]How do i align both textviews on top of the drawable preventing them to pile up on eachother
Hello stackoverflow members. 您好stackoverflow成员。 i am trying to achieve this: http://imgur.com/dqwOAOf
我正在尝试实现这一目标: http : //imgur.com/dqwOAOf
But for some reason the two texts cant take these positions like this http://imgur.com/lyYg8Ei Could anyone explain what i am doing wrong? 但是由于某种原因,这两个文本不能像这样http://imgur.com/lyYg8Ei担任这些职务。有人可以解释我在做什么错吗? and please forgive my artistic talents.
请原谅我的艺术才华
i have added the whole xml file. 我已经添加了整个xml文件。
The idea is that the two textviews timer and typegekookt are displayed in the center of backgroundtypegekookt evenly spaced out. 这个想法是两个textviews计时器和typegekookt显示在等距的backgroundtypegekookt的中心。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="@+id/eggContainer"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView android:id="@+id/eggtimerimage"
android:src="@drawable/eiwit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_vertical"
/>
<ImageView android:id="@+id/backgroundtypegekookt"
android:src="@drawable/timerwijzer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
/>
<TextView
android:id="@+id/typegekookt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="zacht"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_alignTop="@+id/divider2"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:00"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@+id/divider2"
/>
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="@+id/divider1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/eggtimerimage"
android:layout_marginBottom="-30dp"
/>
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="@+id/divider2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/backgroundtypegekookt"
android:layout_alignStart="@+id/backgroundtypegekookt"
android:layout_alignRight="@+id/backgroundtypegekookt"
android:layout_alignEnd="@+id/backgroundtypegekookt" />
</RelativeLayout>
Instead of using the ImageView android:id="@+id/backgroundtypegekookt"
, use a RelativeLayout (or a LinearLayout) with that background ( android:background="@drawable/timerwijzer"
), and put your TextViews in it 与其使用ImageView
android:id="@+id/backgroundtypegekookt"
, android:background="@drawable/timerwijzer"
使用具有该背景( android:background="@drawable/timerwijzer"
)的RelativeLayout(或LinearLayout),然后将TextViews放入其中
This is what I mean: 这就是我的意思:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/eggContainer"
android:layout_height="wrap_content"
android:padding="15dp"
>
<ImageView
android:id="@+id/eggtimerimage"
android:src="@drawable/eiwit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_vertical"
/>
<LinearLayout
android:id="@+id/backgroundtypegekookt"
android:background="@drawable/timerwijzer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/typegekookt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="zacht"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/timer"
android:below="@id/typegekookt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="10:00"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_centerHorizontal="true"
/>
</LinearLayout>
<!-- You can use 2 Views instead of 2 TextViews, more efficiently -->
<!-- Anyway, in your screenshots I only see 1 - I guess you'll have to fix that -->
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="@+id/divider1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-30dp"
/>
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignLeft="@id/backgroundtypegekookt"
android:layout_alignStart="@id/backgroundtypegekookt"
android:layout_alignRight="@id/backgroundtypegekookt"
android:layout_alignEnd="@id/backgroundtypegekookt"
/>
</RelativeLayout>
I also fixed the deprecated fill_parent
to match_parent
and @+id
(anticipated reference) to @id
(reference), where needed. 我还根据需要将不推荐使用的
fill_parent
固定为match_parent
并将@+id
(预期参考)固定为@id
(参考)。
Also see my comments in the layout avout the 2 last views. 另请参阅布局中关于最后2个视图的我的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.