在父级上均匀分布android垂直搜索栏
我用下面的代码创建了一个“标准”垂直搜索栏(在这里发布了很多次) 现在我想在我看来使用其中的6个。如果我只是使用RelativeLayout将它们放在一起,一切都很好(无法发布图像,缺乏声誉…) 但是,我希望它们在视图中水平均匀分布,如果我在布局XML中将它们添加为LinearLayout的子级,并为每个子级设置一个权重1,progressDrawable(我认为是“条”)将用一点填充填充整个视图宽度,拇指将放在左侧 现在我明白了为什么会发生这种情况,但我不知道如何解决它。也就是说,我如何保持默认比例,并且仍然在视图中以progressDrawable和thumb为中心均匀分布搜索杆 一般来说,我对android和Java开发还不熟悉,所以请耐心听我说。我希望我能设法解释这个问题 提供胖乎乎的seekbar的XML布局如下所示:在父级上均匀分布android垂直搜索栏,android,seekbar,Android,Seekbar,我用下面的代码创建了一个“标准”垂直搜索栏(在这里发布了很多次) 现在我想在我看来使用其中的6个。如果我只是使用RelativeLayout将它们放在一起,一切都很好(无法发布图像,缺乏声誉…) 但是,我希望它们在视图中水平均匀分布,如果我在布局XML中将它们添加为LinearLayout的子级,并为每个子级设置一个权重1,progressDrawable(我认为是“条”)将用一点填充填充整个视图宽度,拇指将放在左侧 现在我明白了为什么会发生这种情况,但我不知道如何解决它。也就是说,我如何保持默
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/cream"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".EditInst"
android:padding="2dp">
<LinearLayout android:id="@+id/header"
android:background="#ffffbc40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView android:id="@+id/instTxt"
android:textIsSelectable="false"
android:textColor="#ff000000"
android:textSize="18sp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
</LinearLayout>
<LinearLayout android:id="@+id/SeekBars"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header">
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/f0SeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/f1SeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/f2SeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/cSeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/sSeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/dSeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
</LinearLayout>
</RelativeLayout>
最简单的方法可能是在中间添加另一层。您可以在当前搜索栏所在的位置使用类似于
FrameLayout
的东西,这样您就有了“胖乎乎的FrameLayout
s”,然后在每个FrameLayout
s中放置一个搜索栏。非常感谢!这和每个SeekBar上的“android:layout_gravity=“center”都起到了作用。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/cream"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".EditInst"
android:padding="2dp">
<LinearLayout android:id="@+id/header"
android:background="#ffffbc40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView android:id="@+id/instTxt"
android:textIsSelectable="false"
android:textColor="#ff000000"
android:textSize="18sp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
</LinearLayout>
<LinearLayout android:id="@+id/SeekBars"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header">
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/f0SeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/f1SeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/f2SeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/cSeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/sSeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
<com.plainfieldworks.nofiseq.VerticalSeekBar android:id="@+id/dSeekBar" android:padding="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="fill_parent"/>
</LinearLayout>
</RelativeLayout>