2012-02-21 8 views
18

私はレイアウトを持って揃えImageViewのアンドロイド

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF"> 

    <TextView android:id="@+id/groupname" 
     android:paddingLeft="50px" 
     android:textSize="16px" 
     android:background="#FFFFFF" 
     android:textColor="#000000" 
     android:textStyle="normal" 
     android:layout_width="wrap_content" 
     android:layout_height="50px"/> 
    <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_marginRight="6dp" 
      android:background="#ffffff" 
      android:src="@drawable/sort"/> 

</LinearLayout> 

Rendering like this presently I want to render like this

レンダリングは、最初の画像のように、今起こっているが、私は第二の画像に完全に右詰めのようにレンダリングしたかったです。任意の助けが役に立つでしょう。

ご返信をお待ちしております。ありがとう。

+1

ソリューションとしてRelativeLayoutを述べた人はかなり適切なソリューションを持っています。私たちに働かないということは、あなた自身や誰かを助けることではないということだけです。 – Maurice

+0

@Mauriceありがとう、しかし、私の答えは、RelativeLayoutのためにうまくいかなかった、それは私が答えたものです。 – Mukunda

答えて

43
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF"> 

    <TextView android:id="@+id/groupname" 
     android:paddingLeft="50dp" 
     android:textSize="16dp" 
     android:textColor="#000000" 
     android:textStyle="normal" 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:layout_weight="0.9" 
     android:background="@color/black"/> 
    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="#ffffff" 
      android:src="@drawable/checkin" 
      android:layout_weight="0.1"/> 

</LinearLayout> 

、これを試してみて、これが役立つことを願っています。

Prview1 enter image description here

+0

ありがとう。完璧に動作します。 – Mukunda

+0

これは、画像ビューの幅が固定されている場合は、画像ビューのlayout_weightなしでも行うことができます。 textviewのlayout_weightに値1を設定するだけです。 –

11

親レイアウトとしてRelativeLayoutを使用します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

    <TextView android:id="@+id/groupname" 
       android:paddingLeft="50px" 
       android:textSize="16px" 
       android:textColor="#000000" 
       android:textStyle="normal" 
       android:layout_width="wrap_content" 
       android:layout_height="50px"/> 

    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="6dp" 
      android:src="@drawable/ncc"/> 

</RelativeLayout> 
+1

ありがとうございます。 – Mukunda

3
<?xml version="1.0" encoding="utf-8"?> 

<TextView android:id="@+id/groupname" 
    android:paddingLeft="50px" 
    android:textSize="16px" 
    android:background="#FFFFFF" 
    android:textColor="#000000" 
    android:textStyle="normal" 
    android:layout_width="wrap_content" 
    android:layout_height="50px"/> 
<ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:layout_marginRight="6dp" 
     android:background="#ffffff" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/sort"/> 

+0

ありがとうございますが、これは動作していません。 – Mukunda

0

いずれ次のようにRelativeLayoutとのTextViewのプロパティセットを使用する:

layout_width=fill_parent 
layout_height=wrap_content 
left_of="@+id/imgView" 

とImageViewの

にします
layout_width=wrap_content 
layout_height=wrap_content 
alignparentright=true 
+0

ありがとうございました。 – Mukunda

23

利用アンドロイド:テキストビューのために= "1" layout_weight

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF"> 

    <TextView android:id="@+id/groupname" 
    android:paddingLeft="50px" 
    android:textSize="16px" 
    android:layout_weight="1" 
    android:background="#FFFFFF" 
    android:textColor="#000000" 
    android:textStyle="normal" 
    android:layout_width="0dp" 
    android:layout_height="50px"/> 
<ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:layout_marginRight="6dp" 
     android:background="#ffffff" 
     android:src="@drawable/sort"/> 

</LinearLayout> 
+0

ありがとう、これは良いです! – AVEbrahimi

+0

完璧なソリューション! – Surekha

0

あなたはXMLでそのようなことを追加する必要があります...あなたは右揃えたいオブジェクトに...

android:layout_alignParentRight="true" 
android:layout_marginRight="..dp" 
+0

ありがとうございますが、これは、異なる画面にどのように濃度ピクセルを設定するかというと、これは可能ではありません。 – Mukunda

+0

フォルダ/大、/ xlarge、/異なる画面用の小さいレイアウトを作成することによって... – timonvlad

3

RelativeLayoutを試してください。

<?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" 
    android:background="#FFFFFF"> 

    <TextView 
     android:id="@+id/groupname" 
     android:layout_width="wrap_content" 
     android:layout_height="50px" 
     android:background="#FFFFFF" 
     android:paddingLeft="50px" 
     android:textColor="#000000" 
     android:textSize="16px" 
     android:textStyle="normal" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:background="#ffffff" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
+0

ありがとう、これも動作していません。ありがとう。 – Mukunda

関連する問題