0

TextView にテキストが提供されていない場合、レイアウト内の textView が占める領域が削除されるため、テキストが必要な空白の領域がなくなり、他の何かで使用できるようになります。

ここに画像の説明を入力

ここでは、情報が「2013 年 9 月 17 日」の下にあるギャップを見ることができますが、そのスペースを削除してレイアウトの見栄えを良くしたい場合、レイアウトとして他のセクションで TextView を使用できるようにするにはどうすればよいでしょうか。上記のレイアウトは ListView の一部であるため、TextView を削除しただけでは、日付部分の下に情報があれば表示されません。情報は、インターネット上でホストされている XML ファイルから受信されています。申し訳ありませんが、これを非常に悪く説明しました。

オンラインでホストされている XML ファイル:

<games_list>
<game>
<id>1</id>
<title>Grand Theft Auto 5</title>
<date1>17th September 2013</date1>
<date2/>
<date3/>
<platforms>360, PS3</platforms>
<thumb_url>
http://launchpadsoftware.webs.com/ReleaseDates%20Web%20Data/gta5thumb.jpg
</thumb_url>
</game>
<game>
<id>2</id>
<title>Grand Theft Auto 5</title>
<date1>17th September 2013</date1>
<date2/>
<date3/>
<platforms>360, PS3</platforms>
<thumb_url>
http://api.androidhive.info/music/images/eminem.png
</thumb_url>
</game>
</games_list>

list_row.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_card"
android:orientation="horizontal"
android:padding="5dip" >

<!--  ListRow Left sied Thumbnail image -->
<ImageView
    android:id="@+id/list_image"
    android:layout_width="50dip"
    android:layout_height="50dip"
    android:src="@drawable/gta5thumb"
    android:padding="3dip"
    android:background="@drawable/image_bg"
    android:layout_centerVertical="true"/>





<!-- Title Of Song-->
<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@id/list_image"
    android:layout_toRightOf="@id/list_image"
    android:text="Grand Theft Auto 5"
    android:textColor="#040404"
    android:textSize="18sp"
    android:layout_marginLeft="4dp"
    android:textStyle="bold"/>

<!-- Artist Name -->
<TextView
    android:id="@+id/date1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:textColor="#343434"
    android:textSize="14sp"
    android:layout_marginTop="1dip"
    android:layout_toRightOf="@id/list_image"
    android:layout_marginLeft="4dp"
    android:text="17th September 2013" />
<TextView
    android:id="@+id/date2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/date1"
    android:textColor="#343434"
    android:textSize="14sp"
    android:layout_marginTop="1dip"
    android:visibility="visible"
    android:layout_marginLeft="4dp"
    android:layout_toRightOf="@id/list_image"
    android:text="17th September 2013" />
<TextView
    android:id="@+id/date3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#343434"
    android:textSize="14sp"
    android:layout_marginLeft="4dp"
    android:text="17th September 2013"
    android:layout_below="@+id/date2"
    android:layout_toRightOf="@+id/list_image"/>

<!-- Rightend Duration -->
<TextView
    android:id="@+id/platforms"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@id/title"
    android:gravity="right"
    android:text="360, PS3"
    android:layout_marginRight="3dip"
    android:textSize="12sp"
    android:textColor="#10bcc9"
    android:textStyle="bold"/>

 <!-- Rightend Arrow -->    
 <ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/arrow"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"/>

</RelativeLayout>
4

2 に答える 2

0

カスタム リスト アダプターでは、テキストのないテキストビューを非表示にする必要があります

textview.setVisibility(View.GONE);

そしてxmlでは使用する必要があります

android:layout_centerVertical="true"

テキストを持つテキストビューの場合。

于 2013-07-21T13:02:13.937 に答える
0

私はあなたがそれを動的に行うと思うので、あなたはコードでそれを行うことができます。

textView.setVisible(View.GONE);
于 2013-07-21T13:20:40.583 に答える