android - 在两个 TextView 之间定位搜索栏不起作用

标签 android

我在两个 TextView 之间放置了一个搜索栏,但它没有按要求显示。下面是 XML

  <LinearLayout
    android:id="@+id/timerDisplay"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:orientation="horizontal" >

    <!-- Current Duration Label -->
    <TextView 
        android:id="@+id/songCurrentDurationLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="12.00"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:textColor="#eeeeee"
        android:textStyle="bold"/>

    <SeekBar
        android:id="@+id/songProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:progressDrawable="@drawable/seekbar_progress"
        android:thumb="@drawable/seek_handler" />

    <!-- Total Duration Label -->
    <TextView 
        android:id="@+id/songTotalDurationLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:text="10.00"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:textColor="#04cbde"
        android:textStyle="bold"/>
  </LinearLayout>

上面的结果类似于 enter image description here

然而这是想要的结果 enter image description here

我哪里错了?我不想硬编码 seekbar 的 layout_width,应该更改什么?

最佳答案

使用**android:weightSumandroid:layout_weight**

<LinearLayout
    android:id="@+id/timerDisplay"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:orientation="horizontal"
    android:weightSum="100" >

    <!-- Current Duration Label -->
    <TextView 
        android:id="@+id/songCurrentDurationLabel"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="12.00"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:textColor="#eeeeee"
        android:textStyle="bold"
        android:layout_weight="10"/>

    <SeekBar
        android:id="@+id/songProgressBar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:progressDrawable="@drawable/seekbar_progress"
        android:thumb="@drawable/seek_handler"
        android:layout_weight="80" />

    <!-- Total Duration Label -->
    <TextView 
        android:id="@+id/songTotalDurationLabel"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:text="10.00"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:textColor="#04cbde"
        android:textStyle="bold"
        android:layout_weight="10"/>
  </LinearLayout>

关于android - 在两个 TextView 之间定位搜索栏不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175350/

相关文章:

android - Contact_ID 列无效 ContactsContract.Contacts

android - 设置应用级代理

android - 访问被拒绝查找属性 "vendor.camera.aux.packagelist"

Android:创建 AVD 的应用程序 Activity

android - layout-finger 和 layout directory 的区别

java - 如何在启动 PlayStore 之前决定应用程序名称

android - 如何仅使用一个应用程序制作嵌入式 Android 操作系统?

android - 平均值计算结果为意外的 0

android - 使用 ViewPager 和 fragment

android - ViewModel 观察被触发两次以上,而 API 仅命中一次