将Seekbar对齐ImageView右侧(图标)

时间:2016-02-03 16:58:03

标签: android android-layout seekbar android-seekbar

Layout problem

正如您所看到的,搜索栏有点偏高,因此无法正确对齐图标。有没有一种简单的方法来解决它?我在图标上设置了固定大小,因为我希望它看起来大于24dp,类似于Androids音频设置。

<?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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ui.MainActivity">

    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar"
        android:layout_below="@+id/textView"
        android:layout_toRightOf="@+id/imgRing"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignBaseline="@+id/imgRing"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Ring volume"
        android:id="@+id/textView"

        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
     />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:id="@+id/imgRing"
        android:background="@drawable/ic_notifications_black_24dp"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

只需将您的Seekbar更新到与ImageView相同的高度:

<?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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ui.MainActivity">

    <!-- SeekBar height the same size as your ImageView-->
    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:id="@+id/seekBar"
        android:layout_below="@+id/textView"
        android:layout_toRightOf="@+id/imgRing"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignBaseline="@+id/imgRing"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Ring volume"
        android:id="@+id/textView"

        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
     />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:id="@+id/imgRing"
        android:background="@drawable/ic_notifications_black_24dp"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>