2011-12-14 11 views
0

私は、水平レイアウトにテキストを左に表示しようとしており、次に2つの画像を画面の右側に並べて表示しようとしています。 私はそれを行うための方法を見つけることができません...Androidの基本レイアウト

それは次のようになります。

[テキストの一部------------------- IMG1-IMG2]

ご存知ですか?ここで

+1

試したことでうまくいかないのは何ですか? –

+4

これは 'RelativeLayout'で簡単に行うことができます。このレイアウトで作業する方法がわからない場合は、[Hello RelativeLayout](http://developer.android.com/resources/tutorials/views/hello-relativelayout.html)を参照してください。それは私の意見では、アンドロイドのための最も有用な/柔軟なレイアウトのタイプですので、どのようにそれを使用する方法を学ぶ価値があります。それを使用して問題がある場合は、戻ってきて、あなたが試したものを見せてください。 :) –

+0

@Aaron McIver relativeLayoutを使用すると、私ができることはすべて [一部のテキスト-IMG1 ------------------- IMG2] またはIMG1とIMG2がある互いにオーバーラップしています... – user1026605

答えて

1

なぜ相対レイアウトを使用しないのですか?それはこの状況には理想的です。それでも線形レイアウトを使用する場合は、レイアウトxmlファイルのtextviewにandroid:paddingRight='X dipを使用してみてください。ここで、Xは希望するパディングを表す整数です。

編集: 私はあなたが相対レイアウトで行くことに決めました。下のあなたを助ける:

<?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"> 
<TextView 
android:id="@+id/sometext" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Type here:" android:layout_alignParentLeft="true"/> 
<ImageView 
android:id="@+id/image2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@android:drawable/image2" 
android:layout_alignParentRight="true"/> 
<ImageView 
android:id="@+id/image1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_toLeftOf="@id/image2"/> 
</RelativeLayout> 
+0

RelativeLayoutで動作させたいだけでした。あなたのソリューションが動作している多くのありがとう! – user1026605

0

は、これを操作するための出発点である:

からComining Multiple Layouts
- Example Layouts

私はレイアウト例の一つは、あなたが望む結果を得るために変更することができると思います。

0

あなたは単にLinearLayoutまたはRelativeLayoutを使用していることを行うことができます。

最初のケースでは、子ビュー(TextView/EditTextと2画像)を積み重ねるのにandroid:orientation="horizontal"を使用する必要があります。

第2の場合は、android:layout_<direction>android:layout_alignParent_<direction>を使用して必要なものを達成する必要があります。時間をかけて遊んでください。詳細については、リンクされたチュートリアルをご覧ください。

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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="This is portion of right" /> 

    <ImageView 
     android:id="@+id/img2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:src="@mipmap/ic_launcher" /> 

    <ImageView 
     android:id="@+id/img1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/img2" 
     android:src="@mipmap/ic_launcher" /> 
</RelativeLayout>