2017-02-27 1 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이 자동으로 수행하는 작업입니다. 그것은 앞에서 뒤를 향해서 렌더링됩니다. 순차적으로 자식을 그립니다. 첫 번째 자식이 먼저 그려지며 두 번째 자식이 그 위에 놓이게되고 세 번째 자식이 그 위에 놓입니다.

당신이 이미 가지고있는 것과 유사하지만 현재 버튼이 포함 된 중복 FrameLayout이없는 이유는 무엇입니까?

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

나는 당신을 오해하고 있습니까?

+0

나는 이것을 시도 할 것이다. 마지막으로 나는 이미지를 framelayout 안에 넣지 않고 버튼 위에 표시하지 않을 것이다. 결과에 대한 업데이트를 게시합니다. – Greg432

+0

몇 시간 동안 놀았지만 "중복 FrameLayout"없이는 오브젝트의 순서 (btn, tv, iv)와 상관없이 작동하지 않습니다. ImageView와 TextView는 절대로 다른 방식으로 표시되지 않습니다. 'background = ""'또는 이미지 버튼 대신'src = ""'를 사용해야합니까? – Greg432

+0

좋아,'Button'을'ImageButton'으로 바꾸면됩니다. – Greg432

관련 문제