なぜTextViewsはRelativeLayoutにお互いに実行しています
-
20-09-2019 - |
質問
私はお互いに実行しているRelativeLayoutで同じ高さにある2つのTextviewsに問題があります。
私は、次のレイアウトを使用します。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/icon" />
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="NameNameNameNameNameNameName"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/logo"
android:gravity="clip_horizontal"
android:lines="1" />
<TextView
android:id="@+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/nrcoupons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:layout_alignRight="@id/information"
android:layout_alignBottom="@id/logo" />
<TextView
android:id="@+id/subcategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subcategory"
android:layout_alignLeft="@id/name"
android:layout_alignBottom="@id/logo" />
</RelativeLayout>
これは私にこのビューを提供します:
altテキストhttp://janusz.de/~janusz/view.pngする
すべては、私は他の上に1と同じ画面スペースに表示されている2つのtextviews名および情報以外にそれを必要とするようです。
どのように私はこれを避けることができますか?
解決
あなたの@+id/name
のTextView
については、右側にあるものは何でもandroid:layout_toLeftOf="..."
ためTextView
を追加します。スクリーンショットおよびXMLは、(スクリーンショットが上書きのTextViewに「距離」を持っているように見えますが、XMLにはない)のラインアップしていないようですので、私はこれがどのウィジェット完全に一定ではないんです。
あなたは、Android 1.5をターゲットにしている場合、あなたは彼らがandroid:layout_toLeftOf
またはandroid:layout_toRightOf
から参照される前に、ウィジェットが定義されているようにXMLでウィジェットを注文する必要があります。あなたは、Android 1.6以降をターゲットにしている場合にのみ、あなたは彼らがどのような順序でも持つことができますが、任意の個別IDの最初の出現は、最初に出現したが、代わりに+
属性のandroid:layout_toLeftOf
属性であっても、android:id
サインを持っている必要があります。
他のヒント
あなたのnamenamenameのTextViewには、幅= fill_parentに設定されている;)