簡體   English   中英

我如何將兩個textview對齊在可繪制對象的頂部,以防止它們彼此堆積

[英]How do i align both textviews on top of the drawable preventing them to pile up on eachother

您好stackoverflow成員。 我正在嘗試實現這一目標: http : //imgur.com/dqwOAOf

但是由於某種原因,這兩個文本不能像這樣http://imgur.com/lyYg8Ei擔任這些職務。有人可以解釋我在做什么錯嗎? 請原諒我的藝術才華

我已經添加了整個xml文件。

這個想法是兩個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>

與其使用ImageView android:id="@+id/backgroundtypegekookt"android:background="@drawable/timerwijzer"使用具有該背景( android:background="@drawable/timerwijzer" )的RelativeLayout(或LinearLayout),然后將TextViews放入其中

這就是我的意思:

<?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>

我還根據需要將不推薦使用的fill_parent固定為match_parent並將@+id (預期參考)固定為@id (參考)。

另請參閱布局中關於最后2個視圖的我的評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM