마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

프래그먼트 버튼 질문드려요~

0 추천

버튼 클릭시 숫자 증가 예제를 보면서 프래그먼트에서 다음과 같이 기입을 하였는데요 

JAVA

@Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View RootView = inflater.inflate(R.layout.content_main, container, false);
        // onCreateView = Layout을 inflater하여 View작업을 하는 곳
        final ArcSeekBar arcSeekBar = (ArcSeekBar)RootView.findViewById(R.id.seekArc);
        mhztext = (TextView)RootView.findViewById(R.id.hztext);
        mtimebar = (TextView)RootView.findViewById(R.id.timebar);

        // 타이머 버튼
        left_btn = (Button)RootView.findViewById(R.id.left_btn);
        left_btn.setOnClickListener(this);
        right_btn = (Button)RootView.findViewById(R.id.right_btn);
        right_btn.setOnClickListener(this);
        // hz 버튼
        hz_left=(Button)RootView.findViewById(R.id.hz_left);
        hz_left.setOnClickListener(this);
        hz_right=(Button)RootView.findViewById(R.id.hz_right);
        hz_right.setOnClickListener(this);

        arcSeekBar.setProgress(0);
        mhztext.setText("");

        return RootView;
    }    

    @Override
    public void onClick(View v) {
        Log.d("Content_Main","onClick:"+v.getId());
        switch(v.getId()) {
        // 시간 -10초
        case R.id.left_btn:
            count-=10;
            mtimebar.setText(""+count);
            break;

        // 시간 +10초
        case R.id.right_btn:
            count+=10;
            mtimebar.setText(""+count);
            break;

        // Hz -1
        case R.id.hz_left:
            count--;
            mhztext.setText(""+count);
            break;

        // Hz +1
        case R.id.hz_right:
            count++;
            mhztext.setText(""+count);
            break;
        default:
            break;
        }

xml

<?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:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Activity_Main"
    tools:layout_editor_absoluteY="56dp"
    tools:showIn="@layout/app_bar_activity_main">

    <android.support.constraint.ConstraintLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <!-- 시간 -->
    <TextView
        android:id="@+id/timebar"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginBottom="300dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="30dp"
        android:gravity="center"
        android:text="0"
        android:textColor="#ffffff"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <!-- 시간 down 버튼 -->
    <Button
        android:id="@+id/left_btn"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginBottom="300dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/arrow_left_black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/timebar"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <!-- 시간 up 버튼 -->
    <Button
        android:id="@+id/right_btn"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginBottom="300dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/arrow_right_black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/timebar"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <!-- Hz -->
    <TextView
        android:id="@+id/hztext"
        android:layout_width="40dp"
        android:layout_height="44dp"
        android:layout_marginLeft="70dp"
        android:layout_marginStart="70dp"
        android:gravity="center"
        android:text="0"
        android:textColor="#ffffff"
        android:textSize="35sp"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <!-- Hz down 버튼 -->
    <Button
        android:id="@+id/hz_left"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_marginLeft="50dp"
        android:layout_marginStart="50dp"
        android:background="@drawable/arrow_left_black"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <!-- Hz up 버튼 -->
    <Button
        android:id="@+id/hz_right"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_marginLeft="110dp"
        android:layout_marginStart="110dp"
        android:background="@drawable/arrow_right_black"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="@+id/imageView" />


    </android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>

 

코드 기입을 하고 나서 테스트 중에 숫자가 변경이 안되서 로그캣 창을 보니 다음과 같이 출력이

되는데 어디서 잘못된지 모르겠어서 질문드려요

10-10 21:30:00.562 17289-17289/com.abc.abcD/ViewRootImpl@ed3ecde[Activity_Main]: ViewPostIme pointer 0
10-10 21:30:00.659 17289-17289/com.abc.abcD/ViewRootImpl@ed3ecde[Activity_Main]: ViewPostIme pointer 1
10-10 21:30:00.756 17289-17289/com.abc.abcD/ViewRootImpl@ed3ecde[Activity_Main]: ViewPostIme pointer 0
10-10 21:30:00.832 17289-17289/com.abc.abcD/ViewRootImpl@ed3ecde[Activity_Main]: ViewPostIme pointer 1

익명사용자 님이 2018년 10월 10일 질문
<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:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Activity_Main"
    tools:layout_editor_absoluteY="56dp"
    tools:showIn="@layout/app_bar_activity_main">
 
    <android.support.constraint.ConstraintLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

왜 콘스트레인트 레이아웃이 겹쳐있나요?
이너 레이아웃이 x , y 값이 없어서 하위 뷰들의 실제 영역도 틀어진 것 같아요.
이너뷰를 제거해보심이 어떨까요

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...