2011-12-21 19 views
4

私は私のAndroidアプリに以下のような効果を達成したい:背景としていくつかのテキストビューをアンドロイドの画像ビューに重ねる方法は?

enter image description here

私は9-パッチPNG画像を使用します。いただきました!間違った任意のアイデアを、私はちょうど1つのテキストビュー

<ImageView 
    android:id="@+id/myImageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/rowimage" /> 

<TextView 
    android:id="@+id/myImageViewText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/myImageView" 
    android:layout_alignTop="@+id/myImageView" 
    android:layout_alignRight="@+id/myImageView" 
    android:layout_alignBottom="@+id/myImageView" 
    android:layout_margin="1dp" 
    android:gravity="center" 
    android:text="Hello" 
    android:textColor="#000000" /> 

でこのようにそれを試してみました。しかし、これは私が結果として何を得る

enter image description here

のですか?どのようにして最初のイメージから効果を得ることができますか?

編集:

私は今、私は

enter image description here

なぜ九パッチ画像をテキストにスケールしない結果を以下の取得、相対的なレイアウトに私のXMLを更新?

+0

あなたはレイアウトの背景としてあなたの@描画可能/ rowimageを入れ、その後、このレイアウトでは、あなたのTextViewを入れてみてくださいました親ビュー – Pinki

+0

として相対的なレイアウトを使用します。 –

+0

@ ArtWorkADどのレイアウトを選択したかを示すレイアウトを表示してください –

答えて

4

最初のソリューションの幅がfill_parentにsettedされRelativeLayoutを追加し、そのためのbackgroundとしてあなたninePatchの画像を設定し、それはこのようにあなたのTextViewsを追加しよう:

<RelativeLayout 
    android:id="@+id/layoutTextViews" 
    android:layout_width="fill_parent" 
    android:layout_height = "wrap_content" 
    android:background="@drawable/rowimage" 
> 

<TextView 
    android:id="@+id/txtView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_margin="1dp" 
    android:gravity="center" 
    android:text="Hello" 
    android:textColor="#000000" /> 

<TextView 
    android:id="@+id/txtView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_margin="1dp" 
    android:gravity="center" 
    android:text="Right" 
    android:textColor="#000000" /> 

</RelativeLayout> 
+0

、おかげで、完璧な、しかしそれはlayout_alignParentRight /左でなければならない例を与えるだろう、あなたはlayout_プレフィックスを忘れてしまった –

+0

はい私は、 Eclipseでテストせずに書いただけです)。それを聞いてうれしい :) – Houcine

2

使用このレイアウト

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView android:src="@drawable/icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true"/> 
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true"> 
    <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Left Text" android:layout_weight="1.0" /> 
    <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Right Text" android:layout_weight="1.0" /> 
    </LinearLayout> 
</RelativeLayout> 
2

回答がすでに掲載されているが、これは、私はそれを行うだろうかです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:padding="1dp" 
    android:background="@drawable/tile"> 
    <TextView 
     style="@style/textstyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello1"/> 
    <View 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 
    <TextView 
     style="@style/textstyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello2"/> 
</LinearLayout> 

LinearLayoutはninepatchをバックグラウンドとして使用し、内容が伸びるようにします。 中央のビューは、テキスト1とテキスト2の間にギャップを作成します。

2
  <?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="50dp" 
      android:background="@drawable/your background image"> 


     <LinearLayout 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textSize="18sp" 
       android:textStyle="bold" 
       android:singleLine="true" 
       android:text="Subject1"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textSize="18sp" 
       android:textStyle="bold" 
       android:singleLine="true" 
       android:text="Subject2"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textSize="18sp" 
       android:textStyle="bold" 
       android:singleLine="true" 
       android:text="Subject3"/> 

     </LinearLayout> 

    </LinearLayout> 
1
​​

関連する問題