我正在尝试在布局中制作一个带有硬编码宽度的搜索栏,但是,一旦搜索栏的硬编码宽度值超过某个值,搜索栏的宽度将不会反射(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 长。这是布局:
现在,当我将 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>
注意: 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/