-1

私はしばらくの間、これを行うための最良の方法を見つけようとしてきました。私が欲しいのはこのようなものです:

コードで:

<?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であるということです。これになんらかの流動性を持たせたい。

私がこれを望む方法:

プログレスバーの上のスペースは、最初のテキストの上、1番目と2番目のテキストの間、および2番目のテキストとプログレスバーの間の3つの等しい部分に分かれています。

不確定なプログレスバー-垂直方向と水平方向の両方の中央に配置されます。

プログレスバーの下のスペースは、プログレスバーとボタンの間、およびボタンと下部の線形レイアウトの間の2つの等しい部分に分かれています。

これを比較的行う方法はありますか?レイアウトファイルでそれを行うことを好みますが、プログラミングとスペーシングをプログラムで行うこともできます。

4

3 に答える 3

1

を使った大まかなレイアウトは次のRelativeLayoutとおりです。

<RelativeLayout>
<TextView
   android:id="@+id/textView1"
   android:layout_above="@+id/textView2" />

<TextView
    android:id="@+id/textView2"
    android:layout_above="@+id/progressBar1" />

<ProgressBar
  android:id="@+id/progressBar1" />

<Button
   android:id="@+id/button1"
   android:layout_below="@+id/progressBar1" />

<TableRow
   android:layout_below="@+id/button1"
   android:weightSum="1.0">

<Button
   android:layout_weight="0.5" />

<Button
   android:layout_weight="0.5" />

</TableRow>

</RelativeLayout>

注:中央を参照してProgressBar、上下のレイアウトを調整できます。

于 2012-07-04T13:01:49.800 に答える
0

あなたはこれを試すことができます:

<?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:id="@+id/btn_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="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_centerInParent="true" />

    <RelativeLayout
        android:id="@+id/btn_wrapper"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/btn_bar"
        android:layout_below="@id/progressBar1" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Button" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/progressBar1"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <View
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="TextView" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

</RelativeLayout>
于 2012-07-04T12:56:00.087 に答える
0
<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />


<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center"
    android:text="TextView" />

<LinearLayout
    android:id="@+id/pb"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
    android:id="@+id/b1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>


<LinearLayout
    android:id="@+id/b2"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center" >

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

于 2012-07-04T12:53:19.143 に答える