我为ListView构建行布局并遇到问题。
目前我的布局如下:
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout_ROW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
>
<ImageView
android:id="@+id/imageView_albumart"
android:layout_alignParentTop="true"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="5dp"
android:background="@color/black"
android:visibility="visible"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/txt_titel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/txt_artist"
android:layout_alignTop="@+id/imageView_albumart"
android:layout_toRightOf="@+id/imageView_albumart"
android:singleLine="true"
android:text="Titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="18dp"
android:textSize="17dp"
android:layout_toLeftOf="@+id/imageView_eq_animation"
android:layout_alignLeft="@+id/txt_artist"
android:layout_alignStart="@+id/txt_artist" />
<TextView
android:id="@+id/txt_artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView_albumart"
android:layout_marginBottom="16dp"
android:layout_toRightOf="@+id/imageView_albumart"
android:text="Artist"
android:singleLine="true"
android:textSize="13dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toLeftOf="@+id/imageView_eq_animation" />
<ImageView
android:id="@+id/imageView_eq_animation"
android:layout_width="30dp"
android:layout_height="70dp"
android:src="@drawable/ic_equalizer1_white_36dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
android:layout_alignParentLeft="@+id/txt_artist"
android:layout_alignBottom="@+id/imageView_albumart" />
<TextView
android:id="@+id/txt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0:00"
android:singleLine="true"
android:textSize="10dp"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="@+id/txt_titel"
android:layout_alignParentRight="true" />
</RelativeLayout>
现在,当我想将imageView_albumart
的可见性更改为android:visibility="gone"
时,我得到了以下结果:
你能看到我的格式问题在哪里吗?我只是想隐藏imgAlbumart所以Title和Artist TextViews是独立的。
答案 0 :(得分:0)
将视图的可见性设置为 View.INVISIBLE ,而不是 View.GONE
答案 1 :(得分:0)
尝试这样,您可以使用RelativeLayout和LinearLayout的组合设计UI。在Google中搜索Android中的设计模式和布局使用情况。你会得到想法。
<?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="match_parent"
android:background="@null"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView_albumart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:background="@android:color/darker_gray"
android:visibility="visible" />
<RelativeLayout
android:id="@+id/RelativeLayout_ROW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@null">
<TextView
android:id="@+id/txt_titel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:singleLine="true"
android:text="Titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17dp" />
<TextView
android:id="@+id/txt_artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_titel"
android:layout_marginBottom="16dp"
android:singleLine="true"
android:text="Artist"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="13dp" />
<ImageView
android:id="@+id/imageView_eq_animation"
android:layout_width="30dp"
android:layout_height="70dp"
android:layout_alignBottom="@+id/txt_artist"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_game"
android:visibility="gone" />
<TextView
android:id="@+id/txt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView_eq_animation"
android:singleLine="true"
android:text="0:00"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10dp"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
答案 2 :(得分:0)
是的,您的布局有问题 将您的布局更改为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout_ROW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/imageView_albumart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="5dp"
android:background="#000"
android:visibility="gone"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/txt_titel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView_albumart"
android:text="Titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="18dp"
android:textSize="17sp"
android:layout_toLeftOf="@+id/imageView_eq_animation"
/>
<TextView
android:id="@+id/txt_artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView_albumart"
android:layout_marginBottom="16dp"
android:layout_toRightOf="@+id/imageView_albumart"
android:text="Artist"
android:singleLine="true"
android:layout_below="@+id/txt_titel"
android:textSize="13dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toLeftOf="@+id/imageView_eq_animation" />
<ImageView
android:id="@+id/imageView_eq_animation"
android:layout_width="30dp"
android:layout_height="70dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="visible"
android:layout_alignParentLeft="@+id/txt_artist"
android:layout_alignBottom="@+id/imageView_albumart" />
<TextView
android:id="@+id/txt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0:00"
android:singleLine="true"
android:textSize="10dp"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="@+id/txt_titel"
android:layout_alignParentRight="true" />
它会做..