0

こんにちは、私は、ページの上部にテキストとその下の画像を持つ単純なアンドロイドページを作成しようとしています。 Iveは線形レイアウトと相対レイアウトの両方を使ってみましたが、テキストの下に表示するイメージを取得できません。イメージがテキストの横にあるか、画面の右側にあるか、相対レイアウトを使用している場合は、イメージ全体が画面全体を占めます。アンドロイドで線形レイアウトを使用するときの画像のプロパティ

これを可能にする画像プロパティはありますか、可能であれば推奨されない絶対レイアウトは使用したくありません。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/gripbckgrnd" > 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="140dp" 
     android:layout_height="211dp" 
     android:src="@drawable/grip1" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="356dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="97dp" 
     android:gravity="center_horizontal" 
     android:text="@string/griptext" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

</LinearLayout> 

おかげLinearLayoutを使用している場合、あなたはそのように配向属性を指定することができ、事前

答えて

1

に:

android:orientation="vertical" 

(ここで

は、私が働いているコードがありますデフォルトは水平です。これにより問題が発生します)

+0

非常に簡単な解決、ありがとう、 – user1161118

+0

あなたは大歓迎です:) – Jave

1

I rあなたが必要でない場合は、dpでもUIコンポーネントを指定しないことをお勧めします。画面のサイズには多少のばらつきがある可能性があります(たとえば、一部のタブレットは1280x800、一部は1280x720)、match_parent、wrap_content、layout_weightなどのように少し伸びて与えることができます。これらの属性のいくつかを使用するサンプルレイアウトを次に示します。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:text="@string/hello" 
    /> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_weight="2" 
    android:src="@drawable/my_drawable" 
    android:contentDescription="@string/describe_drawable"/> 
</LinearLayout> 

また、この例では画像を上に置きます。 :-)

+0

thats素晴らしいヒント – user1161118

関連する問題