У меня есть панель поиска, расположенная непосредственно под ImageView, и я бы хотел, чтобы панель поиска была отцентрирована непосредственно под изображением,
и быть длиной изображения на виде, при этом большой палец находится на полпути вдоль самой полосы
У меня есть следующий макет в моем XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frlayout"
android:layout_weight="0.82"
android:layout_width="match_parent"
android:layout_height="0dp">
<ImageView
android:id="@+id/imageView"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.07"
android:orientation="horizontal"
android:layout_gravity="center"
android:id="@+id/seekbarView">
<SeekBar
android:id="@+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.07"
android:progress="1000"
android:max="2000"
android:layout_gravity="center"
/>
</LinearLayout>
(остальное опущено)
Я думал о том, чтобы поместить отступ к левой стороне панели поиска, чтобы отцентрировать его, и использовать LayoutParams для изменения размера самой панели поиска:
int lefthandside = (findViewById(R.id.seekbarView).getMeasuredWidth() - img2.getWidth())/2;
// img2 is the image that is loaded into the imageview
// We get the leftpadding by finding the total width of the layout, subtracting the width of the image
// and then dividing by two - this tells us the surplus space on either side
LayoutParams lp = new LayoutParams(img2.getWidth(), LinearLayout.LayoutParams.MATCH_PARENT);
simpleSeekBar.setLayoutParams( lp );
// This should hopefully resize the seekbar - the width should be the same as the width of img2
// and the height should be the same as the LinearLayout "container"
simpleSeekBar.setPadding(lefthandside, 0,0,0);
Как видно из прикрепленного снимка экрана соответствующей области, это только частично успешно, но большая часть «дорожки» поисковой панели отсутствует, и в результате я не могу двигать большим пальцем.
Мне кажется, что размер панели поиска был изменен правильно, но мы видим только его хвостовой (правый) конец, и он не отцентрирован, но я все еще примыкаю к левой стороне экрана. По большей части большая часть панели поиска слева от большого пальца теперь скрыта.
Одна вещь, которую я не могу сделать, это удалить «контейнер» линейного макета с панели поиска - я пробовал это, и хотя он работает при центрировании панели поиска, он плохо влияет на остальную часть макета.
Я также пытался удалить атрибуты layout_gravity, но безуспешно.
![screenshot of relevant portion](https://i.stack.imgur.com/27TSR.jpg)