radioButtons를 사용하여 사진간에 변경하고 진행률 표시 줄, textView 및 탐색 표시 줄을 사용하여 선택한 사진의 불투명도 변경 [중복]

Nov 23 2020

저는 올해 자바로 안드로이드 스튜디오를 배우는 학생입니다. 지난주에 진행률 표시 줄, 탐색 표시 줄 및 라디오 버튼에 대해 배웠습니다. 내 숙제는 라디오 버튼을 사용하여 사진 사이를 변경하고 진행률 표시 줄, textView (백분율) 및 탐색 표시 줄을 사용하여 선택한 사진의 불투명도를 변경하는 것입니다.

할 수있는 한 시도해 보았고 실제로 "디자인"을 보면 진행률 표시 줄, 탐색 표시 줄, 텍스트보기가 표시되고 모두 괜찮지 만 앱 (SDK 19에서)을 시작하면 라디오가 버튼은 선택한 사진을 변경하지 않으며 탐색 막대, 진행률 막대 및 텍스트보기도 볼 수 없습니다.

다음은 XML입니다.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="@drawable/appbackground">

    <ImageView
        android:layout_width="318dp"
        android:layout_height="353dp"
        android:src="@drawable/avatar"
        android:layout_gravity="center"
        android:layout_marginBottom="200sp"/>

    <ImageView
        android:id="@+id/element"
        android:layout_width="137dp"
        android:layout_height="128dp"
        android:layout_marginStart="135sp"
        android:layout_marginTop="195sp"
        android:src="@drawable/abc_vector_test"
        android:elevation="2sp"/>


    <RadioGroup
        android:id="@+id/radioG"
        android:layout_width="wrap_content"
        android:layout_height="133dp"
        android:layout_marginTop="400dp"
        android:background="@drawable/background"
        android:orientation="vertical">

        <RadioButton
            android:id="@+id/w"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Water"
            android:textColor="#03A9F4" />


        <RadioButton
            android:id="@+id/e"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Earth"
            android:textColor="#652F00" />


        <RadioButton
            android:id="@+id/f"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Fire"
            android:textColor="#FF5722" />


        <RadioButton
            android:id="@+id/a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Air"
            android:textColor="#9C9C9C" />

    </RadioGroup>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:text="50%"
        android:gravity="center"
        android:layout_marginTop="570sp"
        android:textSize="40sp"/>


    <ProgressBar
        android:id="@+id/prog"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="625sp" />

    <SeekBar
        android:id="@+id/seek"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="650sp"
        android:max="100"
        android:progress="50"
        android:thumb="@drawable/uncleiroh2" />


</FrameLayout>

다음은 자바입니다.

package com.example.avatarphotos;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener {

    private ImageView Element;
    private TextView textView;
    private ProgressBar progressBar;
   private RadioGroup radioGroup;
    private SeekBar seekBar;
    //private RadioButton air;
    //private RadioButton earth;
    //private RadioButton water;
    //private RadioButton fire;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Element = findViewById(R.id.element);
        textView=findViewById(R.id.text);
        progressBar=findViewById(R.id.prog);
        seekBar=findViewById(R.id.seek);
        radioGroup=findViewById(R.id.radioG);
        radioGroup.setOnCheckedChangeListener(this);
        seekBar.setOnSeekBarChangeListener(this);

    }
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
        progressBar.setProgress(i);
        textView.setText(""+i+"%");
        Element.setImageAlpha((int)(i/100.0*255));
    }
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

    }
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

    }



    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i){
            case 0:
                Element.setImageResource(R.drawable.water);
                break;
            case 1:
                Element.setImageResource(R.drawable.earth);
                break;
            case 2:
                Element.setImageResource(R.drawable.fire);
                break;
            case 3:
                Element.setImageResource(R.drawable.air);
                break;
        }
    }

      }

디자인 사진 : 디자인 앱 : 을 작성하는 동안이 오류 메시지가 표시되었으므로 실제로 관련이 있는지 알 수 없습니다. 문제 메시지

답변

FabianMontossi Nov 23 2020 at 23:02

ADB의 최신 ADB 버전으로 업데이트 (또는 전체 Android 스튜디오 업데이트)를 시도해 보는 것이 어떻습니까?

RyanM Nov 24 2020 at 10:29

이 모든 것을 FrameLayout고정 여백이 큰에 넣었습니다 . 누락 된 뷰는 화면에서 벗어난 것일 수 있습니다 ( android:layout_marginTop="625sp"상당히 많이 상쇄하고 있음을 의미합니다. 또한를 사용해야합니다 dp). 미리보기에서 작동하는 이유는 큰 화면에서 어떻게 보이는지 미리보기 때문일 수 있습니다.

그렇지 않으면 FrameLayout이 모든 뷰를 서로 위에 놓기 때문에이 작업을 수행했다고 가정합니다. 당신은 당신의 사용 UI 구축하여이 문제를 해결할 수 ConstraintLayout, 또는 조합 RelativeLayoutLinearLayout. 큰 고정 오프셋이 아닌 서로 및 화면을 기준으로 뷰를 배치합니다.