2017-01-03 3 views
0

私はImageViewとニュースコンテンツを持つTextViewというニュースアクティビティを持っています。私はすべてのスペースにニュースコンテンツを埋めたいと思っています。Android-TextViewをレイアウト内の残りのスペースをすべて埋めるようにします

ニュースの内容は、画像ビューの右側にあるすべてのスペースを埋めるため、画像の右側にテキストが配置されましたが、画像の下に空きスペースがありました。私は、ImageViewTextViewを分離した線形レイアウトにすることに決めました。しかし、イメージから右の領域が満たされた後にテキストが消えた。

問題はhereと表示されます。

私の質問は以下のとおりです。

  1. 私はイメージ図の下に残りのテキストを配置することができますどのように?

  2. 高さ/幅の比率を維持するために写真をどのように作成できますか?ここで

XMLコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.tutorialsbuzz.phrasebook.NewsActivity"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/textViewHeaderNews" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textViewDateNews" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="3dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:text="header" 
      android:textColor="@color/mycolor" 
      android:textSize="16dp" 
      android:textStyle="bold|italic" /> 

     <LinearLayout 
      android:id="@+id/newslayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textViewHeaderNews" 
      android:orientation="horizontal"> 

      <ImageView 
       android:id="@+id/imageViewNews" 
       android:layout_width="165dp" 
       android:layout_height="165dp" 
       android:layout_margin="2dp" 
       android:layout_weight="0" 
       android:scaleType="fitXY" 
       android:src="@drawable/world"/> 

      <TextView 
       android:id="@+id/textViewContentNews" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginTop="1dp" 
       android:layout_weight="1" 
       android:text="jklasdf as ;AJFWADLHF LAS HFLAF VANLASN: l galgsalgngan ;wafasldwlaf alla lnaf alf lg;aeguewaf hwla hfnalgh wa 
       j;fklasgj;s;nva; alsf las ps z; laszfj alsz vzlxg a lrg z;dnlxfdj glzf ;f glaerzlls az 
       ;asdjk aF{ af[ [D{j as ;as ; wjv a jkn da weq g ; aeskj; g ;eakr;ja r" 
       android:textSize="14dp" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/textViewDateNews" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginRight="2dp" 
      android:layout_marginTop="2dp" 
      android:text="date" 
      android:textSize="14dp" /> 

     <TextView 
      android:id="@+id/textViewViewsNews" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/newslayout" 
      android:layout_margin="3dp" 
      android:text="views" 
      android:textSize="13dp" /> 

     <TextView 
      android:id="@+id/textViewRating" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/newslayout" 
      android:layout_margin="3dp" 
      android:text="rating" 
      android:textSize="13dp" /> 

     <TextView 
      android:id="@+id/textViewRatingNews" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@+id/spinnerRatingNews" 
      android:layout_margin="4dp" 
      android:layout_toLeftOf="@+id/spinnerRatingNews" 
      android:text="Գնահատեք." 
      android:textSize="14dp" /> 

     <Spinner 
      android:id="@+id/spinnerRatingNews" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/textViewRating" 
      android:layout_margin="3dp" /> 

    </RelativeLayout> 
</ScrollView> 

答えて

2

(とにかく私のために)説明するのはまあそのかなり複雑。 xmlでそれを行う方法はありませんが、コードで行うことができます。私はあなたが望むのと同じリゾルトを達成するために使った投稿を参照します。 (他のビューの周りにテキストビューを囲む)。

Read this post

上記のように私が使用し、そのかなりいいresaultを持っているものです。

画像のサイズを変更するには、画像のサイズを変更する必要があります。

This is a postリサイズイメージの件について

最初に、画像がXより大きいかどうかをチェックし、必要に応じて因子のサイズを変更します。

+0

ありがとうございます。また、ImageViewで高さ/幅の比率を維持する方法は? –

+0

元の高さ/幅の比率を維持できないように、高さ/幅をハードコーディングしています。代わりにwrap_contentを使用できます。 –

+0

しかし、私は異なるニュースのために、異なる高さと幅で異なる画像が必要です。だから私は自分の見解を維持してImageViewにそれらを配置する必要があります。 –

関連する問題