2017-02-22 10 views
1

私はここで私の最初の質問への答えを見つけた、と私はお互いの隣に私の二つのボタンを設定するために管理:xmlファイル:お互いに隣のボタン - が、それぞれが独自の側面を持ってい

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentTop="false" 
    android:layout_alignParentLeft="false" 
    android:layout_alignParentStart="false" 
    android:layout_alignParentBottom="false" 
    android:layout_alignParentRight="false" 
    android:layout_centerHorizontal="true" 
    android:gravity="center" 
    android:layout_below="@id/description" 
    android:layout_alignParentEnd="false"> 

    <!-- Send it Button --> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/confirm_it" 
     android:textColor="@color/white" 
     android:textSize="15sp" 
     android:layout_weight="0" 
     android:id="@+id/confirm_button" 
     android:backgroundTint="@color/darkCyan" 
     android:onClick="sendName" 
     /> 

    <!-- Skip it Button --> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/skip_it" 
     android:textColor="@color/white" 
     android:textSize="15sp" 
     android:id="@+id/skip_button" 
     android:backgroundTint="@color/darkCyan" 
     android:layout_marginLeft="10dp" 
     android:layout_marginStart="10dp" 
     android:onClick="skipName" 
     /> 
    </LinearLayout> 

を私は、他の何かをしたい私はまだhorizo​​ntaly、互いに横に二つのボタンをしたいが、私は、例えば、各をしたい非常にページの左にあるボタンを送信し、ページの一番右にあるボタンをSKIP:

は、ここで私が欲しいものです:

enter image description here

それは可能ですか?そしてどうやって?

答えて

0

最も簡単な答えはRelativeLayoutLinearLayoutを交換し、アライメント

<RelativeLayout ...> 

    <Button ... 
     android:layout_alignParentLeft="true" /> 
    <Button ... 
     android:layout_alignParentRight="true" /> 

</RelativeLayout> 
+0

。ありがとうございました! – morkuk

0

ニック・カルドーゾの答えが正しいときれいだと私は個人的にそのメソッドを使用するを使用することです。何らかの理由であなたが絶対のLinearLayoutが必要な場合、あなたは次のように聞いて何を達成することができます:

  1. は(0dp幅と0dp高さ)あなたの二つのボタンの間の空のビューを追加します。
  2. layout_weightプロパティをに設定します。

ここ

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="SEND"/> 

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

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="SKIP"/> 

</LinearLayout> 

に役立ついくつかのコードは、ここでは、このコードを取得する結果だだ:

Click for Image!

+0

Claff、私はそれを使用しますが、私のプロジェクトでは時にはLinearLayoutが必要なので、便利です。 – morkuk

0

あなたがのLinearLayoutを使用する必要がある場合。あなたはもっと簡単な方法があります重量またはweightSum

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_weight="1" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

または

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1" 
    android:orientation="horizontal"> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight=".5"/> 

    <Button 
     android:layout_width="0dp" 
     android:layout_weight=".5" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 
0

でのLinearLayoutを試すことができます。 2つのボタンの間にレイアウトを追加し、レイアウトの重みが「1」の場合。 2つのボタンは、必要に応じて調整されます。私は必要なものだけ

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1"> 
     <Button 
      android:text="Button" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/button1" /> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/linearLayout2" 
      android:layout_weight="1" /> <!-- I say there --> 
     <Button 
      android:text="Button" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/button2" /> 
    </LinearLayout> 
</LinearLayout> 
関連する問題