2010-12-04 21 views
1

通知のためにAndroidにレイアウトを作成しようとしています。Androidの横方向のレイアウトコンポーネント

1:垂直 3で開催されるセッションのタイトルとルームでのLinearLayoutを積み重ね:アプリ 2用のアイコンのセッションの開始時間を

問題I私の目標は、次のように表示を持つことです#2はタイトルのサイズに応じて可変幅を持つということです。ユーザーがハンドセットを横向きにして横向きモードに入ると、幅をハードコーディングするとひどく見えます。したがって、ここで私の質問です:#1と#3がそれぞれ左と右に位置合わせされるように3つのコンポーネントをAndroidで水平にレイアウトするにはどうしたらいいですか?

答えて

0

RelativeLayoutをご覧ください。 LinearLayoutの中で、android:layout_toLeftOfとandroid:layout_toRightOfを使用して、途中にあるようにすることができます。私は通常、始めるための簡単な例としてAndroid's Common Layout Object pageを参照しています。私が紛失している小さな警告がまだ残っているかもしれませんが、それは私が一度使った一般的なトリックだと分かりました。

-1

はこのような何かを試してみてください。このような

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ImageView android:id="@+id/img1" 
     android:background="#00F" 
     android:layout_width="100dip" 
     android:layout_height="100dip" 
     android:layout_alignParentLeft="true"/> 
    <ImageView android:id="@+id/img2" 
     android:background="#0F0" 
     android:layout_width="0dip" 
     android:layout_height="100dip" 
     android:layout_toRightOf="@id/img1" 
     android:layout_toLeftOf="@+id/img3"/> 
    <ImageView android:id="@+id/img3" 
     android:background="#F00" 
     android:layout_width="150dip" 
     android:layout_height="100dip" 
     android:layout_alignParentRight="true"/> 
</RelativeLayout> 
+0

OPは、ハードコードされた値を幅に使用しないことを特にOPは述べています。 – user432209

+0

@ user432209これはちょうど例を作ることでした。それはwrap_contentでも行うことができます。私は単純にそれらの値をラップするようにコンテンツをシミュレートするように置きます。 – bigstones

+0

できません。 wrap_contentを使用すると、OPが特に要求している別のアイテムに違反しているので、それはうんざりのように見えます。彼の最後の行については、「残りのスペース」を参照してください。 – user432209

0

何かが合理的な基礎となることがあります

<RelativeLayout 
     android:id="@+id/RelativeLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
     <ImageView 
      android:id="@+id/ImageView01" 
      android:src="@drawable/droid" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true"></ImageView> 
     <LinearLayout 
      android:id="@+id/LinearLayout01" 
      android:layout_below="@id/ImageView01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_alignTop="@+id/ImageView01" 
      android:layout_toRightOf="@+id/ImageView01" 
      android:background="#ffff00"> 
      <TextView 
        android:text="This is wide, wide, title text" 
        android:id="@+id/TextView01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView> 
      <TextView 
        android:text="Short text" 
        android:id="@+id/TextView02" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView> 
      <TextView 
        android:text="Middling wide text" 
        android:id="@+id/TextView03" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView> 

</LinearLayout> 
     <TextView 
      android:text="Right hand text" 
      android:id="@+id/TextView04" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignTop="@+id/ImageView01" 
      android:background="#00ffff"></TextView> 
</RelativeLayout> 

あなたはそれを少し与えるためにハードコードするのLinearLayoutにいくつかの左マージンを好むかもしれませんスペーシングの数

0

これで数時間戦った後、私はlayout_weightの使い方を理解するようになりました。これが問題を解決するための適切な手段であると思われます。

関連する問題