2017-04-08 4 views
-1

xml layout in android studio あなたはAndroidのXMLであなたを助けてくれますか?

<Button 
     android:id="@+id/bintent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Activity" 
     tools:layout_editor_absoluteY="132dp" 
     tools:layout_editor_absoluteX="136dp" /> 

    <Button 
     android:id="@+id/balram1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Alarm" 
     android:layout_centerInParent="true" 
     tools:layout_editor_absoluteY="231dp" 
     tools:layout_editor_absoluteX="136dp" /> 

` but it appears in actual device like this image

ので、私はに何をすべきことは、完全なxmlファイルなしで何が起こっているのか伝えることはほぼ不可能だ実際のデバイス上で

+0

完全なxmlを貼り付けることはできますか? – fightingCoder

+0

この属性はエディタでのみ使用されます。 **ツール:属性はコードから取り除かれ、開発目的のためだけに**使われます。上記のように、ボタンの位置は絶対に表示されます –

答えて

0

それを表示されます。私はあなたがcenterInParent属性を使用しているので、親レイアウトがRelativeLayoutだと思っていますが、どうしてXとYの絶対値を使用しているのか分かりません。 「ツール」名前空間はレイアウトエディタのためだけなので、何もしません。アプリにはまったく影響しません。

あなたの親のレイアウトの幅と高さが "match_parent"ではなく "wrap_content"に設定されていることをお勧めします。そうしないと、アラームボタンが画面の中央に正しく表示されます。

0

ここで問題があるのは、tools:layout_editor_absoluteXtools:layout_editor_absoluteYの属性を使用していることです。 toolsで始まるアトリビュートは、レイアウトデザイナーにのみ適用されます。

ボタンを中央に配置したい場合は、相対レイアウトを親要素として使用し、その中にボタンを置くことができます。私はまた、あなたが使用してますが、どこか心の中で制約レイアウトでされている親のレイアウトを確認していない、他のすべての答えのように

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

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_below="@+id/button2" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="36dp"/> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_alignParentTop="true" 
     android:layout_alignStart="@+id/button3" 
     android:layout_marginTop="42dp"/> 
</RelativeLayout> 
0

:だから、このようなものでなければなりません。はいの場合は、次のコードを使用してください:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <Button 
     android:id="@+id/bintent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Activity" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="150dp" /> 

    <Button 
     android:id="@+id/balram1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Alarm" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginTop="61dp" 
     app:layout_constraintTop_toBottomOf="@+id/bintent" /> 
</android.support.constraint.ConstraintLayout> 
関連する問題