2016-05-11 9 views
0

まず最初にAndroid開発の新機能です。この質問は少年少女に聞こえるかもしれませんが、私はこれに答えられません。私は2つの異なるボタンを並べて表示する必要のあるアプリケーションを持っています。私はこれに必要なタグを指定して、1つのエミュレータで実行しますが、他のエミュレータでは実行しません。アンドロイドアプリで2つのボタンが重複しています

file_name.xml:下のボタンのデザインのための私のコードでボタン1のレイアウトが完了した後に限り、私の知識が行くように、layout_toRightOFはボタン2を配置しますので、

<RelativeLayout> 

    //some code here 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <Button 
     android:id="@+id/button1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:paddingTop="15dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginLeft="36dp" 
     android:layout_marginStart="36dp" 
     android:layout_marginBottom="36dp" /> 
     <Button 
     android:id="@+id/button2" 
     android:layout_width="45dp" 
     android:layout_height="45dp" 
     android:paddingTop="15dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginLeft="96dp" 
     android:layout_marginStart="36dp" 
     android:layout_marginBottom="36dp" 
     android:layout_toRightOf="@+id/button1" /> 
    </RelativeLayout> 

は私のタグに何か問題があります。また、私は両方のためにmarginLeftを静的に提供しました。

両方のボタンが1つのエミュレータ(Google Playサービスがインストールされている)に表示され、他の(Google Playサービスがインストールされていない)エミュレータには表示されません。 Google Playサービスがインストールされていないためですか?私のボタンのデザインに何か不具合がありますか?

どんな種類のヘルプが役に立ちます。

ありがとうございます。

+1

Question、なぜLinearLayoutを使用しないのですか? – cyroxis

+0

LinerLayoutを使ってみましたが、それでも問題は解決しません。 –

+0

両方でalignParentLeft/Startを使用していますが、実際には両方を左に揃えたいのではありませんか?また、 'toRightOf =" @ id/button1 "'(idの+を取り除く)を使用してください。 – zgc7009

答えて

0
<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <Button 
     android:text="1" 
     android:id="@+id/button1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:paddingTop="15dp" 
     android:layout_marginLeft="36dp" 
     android:layout_marginStart="36dp" 
     android:layout_marginBottom="36dp" /> 
    <Button 
     android:text="2" 
     android:id="@+id/button2" 
     android:layout_width="45dp" 
     android:layout_height="45dp" 
     android:paddingTop="15dp" 
     android:layout_marginLeft="96dp" 
     android:layout_marginStart="36dp" 
     android:layout_marginBottom="36dp" 
     android:layout_toRightOf="@+id/button1" /> 
</RelativeLayout 

希望これは

+0

それは私の最後からのタイプミスでした。私は今コードを変更しました。私は単純化するために、ここで私のアプリケーションからボタン1とボタン2に名前を変更しました。 –

+0

答えを得た後にコードを変更しましたか? –

+0

いいえ、私は同じIDを使用しています私のコードで、stackoverflowのtypoを持っていた –

0

は、それは相対的なレイアウトを使用することが必要であるのに役立ちます? 2つのボタンを並べて使用する必要がある場合は、1つの直線的な水平線を使用することができます。そうですね。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="10" 
    android:orientation="horizontal" 
    > 
<Button 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="5" 
    /> 
<Button 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="5" 
    /> 
</LinearLayout> 

相対レイアウトあなたに多くの柔軟性を提供しますが、それは2つの小節のパス(Reference)を行う必要があります。だから、あなたが線形レイアウトにする方が良いです。

+0

*本当に状況によりますか? – cyroxis

+0

それは本当の@cyroxisです。私はちょうどこの質問の要件との文脈で書いた:) – user3354265

+0

@ user3354265 - 私は同じ方法でLinearLayoutを使ってみましたが、それは助けにはなりませんでした。 –

関連する問題