Android SeekBar 长度与 layout_width 值不匹配

标签 android xml android-layout android-view android-seekbar

我正在尝试在布局中制作一个带有硬编码宽度的搜索栏,但是,一旦搜索栏的硬编码宽度值超过某个值,搜索栏的宽度将不会反射(reflect)我设置的值。例如:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <SeekBar
        android:rotation="270"
        android:id="@+id/volumeBar"
        android:layout_width="50dp"
        android:layout_margin="1px"
        android:layout_height="wrap_content"
        android:layout_centerInParent = "true"/>
</RelativeLayout>

产生一个短的搜索栏,因为宽度决定它应该只有 50dp 长。这是布局: enter image description here

现在,当我将 layout_width 更改为 300dp 时,我看到一个截断的搜索栏,它肯定不是 300dp 长。这是文件和布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <SeekBar
        android:rotation="270"
        android:id="@+id/volumeBar"
        android:layout_width="300dp"
        android:layout_margin="1px"
        android:layout_height="wrap_content"
        android:layout_centerInParent = "true"/>
</RelativeLayout>

enter image description here

注意: seekbar 似乎被限制在相对布局(红色矩形)的宽度内,任何时候 seekbar 的长度(由 android:layout_width 指定)都会超过宽度RelativeLayout 的长度是有上限的。 如何让我的搜索栏符合我想要的硬编码长度?

编辑:我在下面包含了父 Activity 的 xml 文件。

<?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:orientation="horizontal"
    android:baselineAligned="false"
    android:keepScreenOn="true">

    <LinearLayout    
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.25"
        android:background="#ffdd4c4f"
        android:orientation="vertical" 
        android:id="@+id/toolbarGestureOverlay" >
        <android.support.v4.view.ViewPager
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v4.view.ViewPager>
    </LinearLayout>  

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_weight="3.75">
    <com.example.project.Multitouch
        android:id="@+id/fretBoard"  
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#3EF20C"/>
    </LinearLayout>    
</LinearLayout>

最佳答案

你可以试试

   <SeekBar
        android:rotation="270"
        android:id="@+id/volumeBar"
        android:layout_width="match_parent"
        android:layout_margin="10dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent = "true"/>

关于Android SeekBar 长度与 layout_width 值不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31371921/

相关文章:

java - 让 Button 重新启动 Activity

android - 删除 fragment 然后重新添加

android - 我可以在 Sony Xperia Play 上开发 Android 应用程序吗?

android - 谷歌支付使用 Stripe : Getting an unexpected developer error in Android

android - Skobbler - 应用程序标签的 ResourceNotFoundException

c# - 我想读取 XML 文件的单个元素并将其输出到 aspx 控件

android - Android 和 iOS 的 Paypal 集成,可能吗?

javascript - 如何清理 XML 对象以避免 "Content not allowed in prolog"错误?

java - Android 多次滑动 View

android - GridLayout 吐出 "inconsistent constraint"调试级日志