【发布时间】:2019-07-29 09:56:54
【问题描述】:
我正在尝试在已加载到 imageview 中的图像下放置一个搜索栏 - xml(如下)工作正常,但 我想做的是将搜索栏的最大长度设置为加载时图像的宽度 并将其置于图像下方。我对这个组做了一些研究,下面的代码调整了栏的大小:
LayoutParams lp = new LayoutParams(img2.getWidth(), 50);
simpleSeekBar.setLayoutParams( lp );
但是,它会将搜索栏放在左边距;如何将其更改为居中? 当用户在横向和纵向之间交替时,我如何让它工作?在两个方向之间切换时,图像居中 - 如何让搜索栏也动态居中?
<?xml version="1.0" encoding="utf-8"?>
<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.80"
android:layout_width="match_parent"
android:layout_height="0dp">
<ImageView
android:id="@+id/ImageTest"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
</FrameLayout>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="1000"
android:max="2000"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".20"
android:background="#004D79"
android:orientation="horizontal">
<Button
android:text="Open File"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/ofbutton" />
<Button
android:text="Save File"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/sfbutton" />
<NumberPicker
android:id="@+id/np"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/drawablenp"
android:layout_centerVertical="true"
/>
</LinearLayout>
【问题讨论】:
标签: android android-layout android-imageview android-xml android-seekbar