2017-07-17 14 views
-1

私はこのレイアウトを以下に示します。私の目標は、プログレスバーとボタンをTextViewの下に、progressBarをボタンのすぐ右側に置くことです。私は何を変えるべきですか?ボタンの右側に進捗バーを追加しますか? (シンプル)

enter image description here

<LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="368dp" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true" 
     android:weightSum="1" 
     tools:layout_editor_absoluteY="0dp" 
     tools:layout_editor_absoluteX="8dp"> 

     <TextView 
      android:id="@+id/myText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:text="hello guys" 
      android:textAlignment="center" 
      android:textAllCaps="false" 
      android:textStyle="italic" /> 

     <ProgressBar 
      android:id="@+id/myProgressBar" 
      style="?android:attr/progressBarStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="20dp" 
      android:visibility="visible" /> 

     <Button 
      android:id="@+id/buttonID" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:enabled="false" 
      android:text="my button" /> 

    </LinearLayout> 

答えて

1

を尋ねる前に、より多くを研究してくださいtoRightOf

を使用することができますRelativeLayoutButtonProgressBarを置きます。そして、layout_centerInParent="true"RelativeLayoutの中央にButtonを移動し、最終的にlayout_toRightOf="@+id/buttonID"

<LinearLayout 
    android:id="@+id/linearLayout" 
    android:layout_width="368dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" 
    android:weightSum="1" 
    tools:layout_editor_absoluteX="8dp" 
    tools:layout_editor_absoluteY="0dp"> 

    <TextView 
     android:id="@+id/myText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:text="hello guys" 
     android:textAlignment="center" 
     android:textAllCaps="false" 
     android:textStyle="italic" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:id="@+id/buttonID" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:enabled="false" 
      android:text="my button" /> 

     <ProgressBar 
      android:id="@+id/myProgressBar" 
      style="?android:attr/progressBarStyle" 
      android:layout_toRightOf="@+id/buttonID" 
      android:layout_centerVertical="true" 
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:visibility="visible" /> 
    </RelativeLayout> 

</LinearLayout> 
+0

答えが受け入れられました –

+0

テキストビューの真ん中にボタン*を配置し、ボタンの右側に進捗バーを追加するにはどうすればいいですか? –

+0

sisa?こんにちはよ、 –

1

代わりLinearLayoutRelativeLayoutを使用してください。 RelativeLayoutを使用すると、あなたが基本的な質問

Layout File - Positioning Item to Right of Another Item (Android)

+0

でボタンの右側に整列ProgressBarを設定するが、私は、プログレスバーとのTextView下のボタンを維持したいです。私はそれのための垂直線形レイアウトが必要ないのですか?いくつかのコードを投稿してください。返信ありがとう –

+0

RelativeLayoutsでは 'layout_below'も使用できます。もう一度質問をする前に、SOの質問とドキュメントを見てください。 –

関連する問題