[Android] Refactor media header view with ConstraintLayout
Geoffrey Métais
git at videolan.org
Sun Feb 5 18:08:26 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sun Feb 5 18:06:47 2017 +0100| [f470140354c1a353751cdc99d18bba58c3475ae4] | committer: Geoffrey Métais
Refactor media header view with ConstraintLayout
> https://code.videolan.org/videolan/vlc-android/commit/f470140354c1a353751cdc99d18bba58c3475ae4
---
.../res/layout/audio_media_switcher_item.xml | 42 ++++++++++++----------
.../videolan/vlc/gui/view/HeaderMediaSwitcher.java | 8 +++--
2 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/vlc-android/res/layout/audio_media_switcher_item.xml b/vlc-android/res/layout/audio_media_switcher_item.xml
index 14f5f7d..4b12189 100644
--- a/vlc-android/res/layout/audio_media_switcher_item.xml
+++ b/vlc-android/res/layout/audio_media_switcher_item.xml
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
+<android.support.constraint.ConstraintLayout
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:paddingTop="5dp"
+ android:paddingLeft="10dip"
+ android:paddingStart="10dip"
android:background="#00000000"
android:orientation="horizontal" >
@@ -10,21 +14,15 @@
android:id="@+id/cover"
android:layout_width="50dip"
android:layout_height="50dip"
- android:paddingLeft="10dip"
+ app:layout_constraintStart_toStartOf="parent"
+ android:paddingRight="10dip"
+ android:paddingEnd="10dip"
android:background="#00000000"
android:visibility="gone" />
- <LinearLayout
- android:layout_width="0px"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:orientation="vertical"
- android:paddingLeft="10dip"
- android:background="#00000000" >
-
<TextView
android:id="@+id/title"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
@@ -32,11 +30,16 @@
android:text="@string/title"
android:textColor="?attr/font_default"
android:background="#00000000"
- android:textSize="16sp" />
+ android:textSize="16sp"
+ app:layout_constraintBottom_toTopOf="@+id/artist"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toEndOf="@id/cover"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/artist"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
@@ -44,7 +47,10 @@
android:text="@string/artist"
android:textColor="?attr/font_light"
android:background="#00000000"
- android:textSize="14sp" />
- </LinearLayout>
+ android:textSize="14sp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/title"
+ app:layout_constraintStart_toEndOf="@id/cover"
+ app:layout_constraintEnd_toEndOf="parent" />
-</LinearLayout>
+</android.support.constraint.ConstraintLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/HeaderMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/gui/view/HeaderMediaSwitcher.java
index aa47d4e..2164f91 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/HeaderMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/gui/view/HeaderMediaSwitcher.java
@@ -22,6 +22,7 @@ package org.videolan.vlc.gui.view;
import android.content.Context;
import android.graphics.Bitmap;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -49,9 +50,12 @@ public class HeaderMediaSwitcher extends AudioMediaSwitcher {
}
titleView.setText(title);
- artistView.setText(artist);
titleView.setSelected(true);
- artistView.setSelected(true);
+ boolean hasArtist = TextUtils.isEmpty(artist);
+ if (hasArtist)
+ artistView.setText(artist);
+ artistView.setSelected(hasArtist);
+ artistView.setVisibility(hasArtist ? GONE : VISIBLE);
addView(v);
}
More information about the Android
mailing list