简体   繁体   English

我如何将两个textview对齐在可绘制对象的顶部,以防止它们彼此堆积

[英]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.

相关问题 如何以编程方式添加TextViews并在布局中对齐它们 - How to programmatically add TextViews and align them in a Layout 如何为此ViewPager和TextViews布局设置适配器? - How do I set up an Adapter for this ViewPager and TextViews layout? 我如何获得LinearLayout,其中组件在Swing中彼此堆叠在一起? - How do I get a LinearLayout where the components are stacked on top of eachother in Swing? 如何保存一些textview并从另一个类加载它们? - How do I save some textviews and load them from another class? 如何在彼此的顶部停止加载数组的元素? - How can I stop elements of an array loading on top of eachother? 创建许多TextView并给它们提供ID之后,我试图用他们的信息打开一个活动。 我怎么做? - After creating many TextViews and giving them IDs, I am trying to open an activity with their information. How do I do that? 如何设置两个彼此相邻的线程池? - How do you set up 2 threadpools that work next to eachother? 如何在Android中注册81个textviews? - how Do i register 81 textviews in android? 当将并发设置为false时,Quartz是否触发“堆积” - Do Quartz triggers “pile up” when you set concurrent to false Libgdx 堆放图片 - Libgdx pile up images
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM