一段时间以来,我一直在努力寻找最好的方法。我想要的是这样的:
使用代码:
<?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" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Button" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/progressBar1"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="49dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/progressBar1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="52dp"
android:text="TextView" />
我有这个布局:
这里的问题是边距是固定的 dpi 量。我想对此进行一些流动性。
我想要这样的方式:
进度条上方的空间被分成 3 个相等的部分,第一个文本上方,第一个和第二个文本之间以及第二个文本和进度条之间
不确定的进度条 - 垂直和水平居中。
进度条下方的空间被分成 2 个相等的部分 - 进度条和按钮之间以及按钮和底部线性布局之间。
有没有办法相对地做到这一点?我更喜欢在布局文件中执行此操作,但我也可以以编程方式进行编程和间距。