【发布时间】:2017-01-03 21:32:32
【问题描述】:
我有一个带有 ImageView 和 TextView 的新闻活动,其中包含新闻内容。我想让新闻内容填满所有空间。
新闻内容填满了图像视图右侧的所有空间,因此文本被放置在图片右侧,但图片下方是空闲空间。我决定将ImageView 和TextView 放在分离的线性布局中。但是在图像右侧的区域被填充后,文本消失了。
问题显示here。
我的问题是:
如何将剩余的文本放在图像视图下?
如何让图片保持他的高宽比?
这是 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>
【问题讨论】:
标签: android xml android-layout textview