2011-06-26 13 views
2

私は相対的なレイアウトでのTextViewとImageViewのを持っている:TextViewの他のアイテムをあまりにも遠くまで拡大する方法を止める方法RelativeLayout?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:paddingLeft="10dip" android:id="@+id/itemRoot" 
    android:clickable="false"> 

    <TextView android:layout_width="wrap_content" android:text="TextView" 
     android:layout_height="wrap_content" android:id="@+id/itemTxt" 
     android:layout_alignParentLeft="true" android:layout_centerVertical="true" 
     android:singleLine="true"></TextView> 
    <ImageView android:id="@+id/delBtn" android:layout_height="wrap_content" 
     android:src="@drawable/delete" android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" android:paddingRight="10dip" 
     android:layout_centerVertical="true"></ImageView> 

</RelativeLayout> 

テキストが長すぎるときしかし、それは「その後、ImageViewのは、すべての方法、画面の最後にその下に行くと重なっと... "しかし、ImageViewがどこで始まるのかを止めたいです。 TextViewをImageViewに引き伸ばすことはできません。なぜなら、私はまた、その外観の下にいくつかの背景があるからです。だから私は2つのビューの間に空白の透明なスペーサーを追加しようとしました:

<TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/spacer" 
     android:layout_alignTop="@+id/itemTxt" android:layout_alignBottom="@+id/itemTxt" 
     android:layout_toLeftOf="@+id/delBtn" android:layout_toRightOf="@+id/itemTxt" 
     android:minWidth="5dip" android:background="@android:color/transparent"></TextView> 

しかし、私はまだ同じ問題があります。スペーサーはテキストが長すぎない限りうまく機能します。しかし、itemTxtはParentLeftに関して定義されているので、画面からスペーサを押し出すだけであり、SDKが円形であると不平を言いながらスペーサに関しても定義できません。

どのような考えですか?

アレックス

答えて

3

これはあなたの探しているものですか?

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:singleLine="true" 
    android:ellipsize="end" 
    android:text="BLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah"/> 

それとも、隣同士に意味ですか:

はImageViewの上記のTextViewを保持しますか?

リニアレイアウト使用します。そのIDはすでに利用可能であり、<TextView>要素に次の属性を追加するようTextView

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/itemRoot" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="10dip" 
    android:orientation="horizontal" 
    android:clickable="false"> 
    <TextView 
     android:id="@+id/itemTxt" 
     android:layout_width="0dip" 
     android:layout_weight="1" 
     android:text="TextView" 
     android:layout_height="wrap_content" 
     android:singleLine="true"/> 
    <ImageView 
     android:id="@+id/delBtn" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:paddingRight="10dip" 
     android:src="@drawable/delete"/> 
</LinearLayout> 
+0

ああ、私は後者を意味した。しかし、それでも動作しませんでしたが、これは私にアイデアを与えました。とにかくRelativeLayoutを追加してビューを追加する必要がありました。アンドロイド:layout_weight = "1"をRelativeLayoutに設定するとうまくいきました。ありがとう。 – Alex

+0

@Alex Ah良い。それについて考えると、LinearLayoutの作業を行うためにおそらくsingleLineの制約を取り除くでしょう。 Congratz on it working – Blundell

1

宣言ImageViewを:すべてのandroid:layout_toLeftOf="@id/delBtn"

+0

それでもImageViewには実際の背景がすべて展開されます。 – Alex

0

まず、それは良いではありませんRelativeLayoutの代わりにLinearLayoutと重みを使用するアイデアです。特に、このLinearLayoutをListViewの内部で使用する場合は注意が必要です。その理由は、Androidでは、体重を使用しているときにAndroidがLinearLayoutをレンダリングするための2つのパスを作成するからです。そしてその事実はあなたのListViewのパフォーマンスを損なう可能性があります。 代わりに、あなたのレイアウトXMLでTextViewの前に、あなたのImageViewのを宣言した後、あなたのTextViewにこの属性を追加する必要が重みを使用する:相対的なレイアウトな問題で

android:layout_toLeftOf="@id/delBtn" 
0

は、エンドポイントを固定することにより解決することができる(右私たちはあたりの左と右のように2つのだけの属性がジョブ android:layout_toRightOfを行うことができます 十分であるようにだけなので、エンドポイントを置く拘束幅に必要とするため、対応する属性に

を使用して)右、上、左。あなたは IDでのTextViewをしたい場合は android:layout_toLeftOf

ますので、=(2ビュー(TextViewの、ImageViewの、またはその他の) ID =強度(左側)とID =時間間に を配置します次 )右のコードを次のようになります。

`<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/place" 
     android:layout_toRightOf="@id/intensity" 
     android:layout_toLeftOf="@id/time" 
     android:text="hokage's house konoha hidden leaf village naruto universe " 
     android:textStyle="bold" 
     android:layout_below="@id/proximity" 
     />` 

上記のコードは、私たちに与えます: image with both atributes of width and large text

を唯一 android:layout_toLeftOf属性が小さいテキストで、その後使用されている

ノート場合は、テキストが右側にallignedれるかもしれませんimage with only one attribute and small text "hokage's home "

ので、両方の属性を使用すると、小さなテキストを使用しても、それは完璧な結果を与える 優れている

関連する問題