2017-02-27 85 views
0

AndroidスタジオでConstraintLayoutを使用してボタンの上に(上に)ImageViewTextViewを重ねようとしています。以下は私が現在私のアプリに使っているものですが、RelativeLayoutsはすべてのデバイスサイズのレイアウトを作るのに非常に時間がかかります。ConstraintLayoutのボタンの上に画像を表示する

News feed picture

は、これが私のXMLである

<FrameLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/frameLayout" 
    tools:layout_constraintTop_creator="1" 
    android:layout_marginStart="48dp" 
    android:layout_marginTop="24dp" 
    tools:layout_constraintLeft_creator="1" 
    ads:layout_constraintLeft_toLeftOf="parent" 
    ads:layout_constraintTop_toTopOf="parent" 
    android:layout_marginLeft="48dp"> 


    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/newfeedbtn" 
      android:background="@drawable/newsfeedbtn" 
      android:visibility="visible" /> 
    </FrameLayout> 


    <ImageView 
     android:layout_width="27dp" 
     android:layout_height="25dp" 
     android:id="@+id/NFRedC" 
     android:layout_gravity="right|top" 
     tools:ignore="ContentDescription" 
     android:background="@drawable/alert" 
     android:gravity="center" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#ffffff" 
     android:id="@+id/NFTextNumber" 
     android:visibility="invisible" 
     android:text="0" 
     android:layout_gravity="right|top" 
     android:layout_marginRight="9dp" 
     android:layout_marginTop="3dp" /> 


</FrameLayout> 

誰もが私は制約を使用してこれを行うことができます方法を知っていますか?レイアウト内のレイアウトを使わずに画像が表示される順序を指定する方法がありますか?例えば、。 Microsoft Officeの「返信」

答えて

1

「レイアウト内のレイアウトを使わずに画像を表示する順序を指定する方法はありますか?」

これは、FrameLayoutが自動的に行うことです。それは、背中合わせにレンダリングします。子を順番に描画します。最初の子が最初に描画され、2番目の子が描画され、3番目の子が描画されます。

あなたは既に持っているものに似ていますが、現在ボタンが含まれている冗長なFrameLayoutを持たないのはなぜですか?

<FrameLayout...> 
    <Button/> 
    <TextView/> 
    <ImageView/> 
</FrameLayout> 

これは意味があるのですか、私はあなたを誤解していますか?

+0

私は最後に、画像をボタンの上に表示せず、フレームレート内に配置しませんでした。結果を更新します。 – Greg432

+0

私はそれを数時間使っていましたが、オブジェクトの順序(btn、tv、iv)にかかわらず、 "冗長なFrameLayout"がなくても動作しませんでした。 ImageViewとTextViewは決して表示されません。 'background =" "'または画像ボタンの代わりに 'src =" "'を使うべきですか? – Greg432

+0

'Button'を' ImageButton'に変更する必要があります – Greg432

関連する問題