रेडियोबटन का उपयोग तस्वीरों के बीच बदलने के लिए और प्रगति बार, टेक्स्ट व्यू और बार का उपयोग करके चुनी हुई तस्वीर की अस्पष्टता को बदलने के लिए [डुप्लिकेट]

Nov 23 2020

मैं एक छात्र हूं जो इस वर्ष अब जावा के साथ एंड्रॉइड स्टूडियो सीखता है। मैंने पिछले सप्ताह प्रगति बार, बार और रेडियो बटन की जानकारी ली है। मेरा होमवर्क तस्वीरों के बीच बदलने के लिए रेडियो बटन का उपयोग करना है और प्रगति बार, टेक्स्ट व्यू (प्रतिशत के लिए) का उपयोग करना है, और चुने हुए फोटो की अस्पष्टता को बदलने के लिए बार की तलाश है।

मैंने जैसा चाहा, और वास्तव में, जब मैं "डिज़ाइन" को देखता हूं, तो मैं अपनी प्रगति बार, सीक बार और टेक्स्ट व्यू देख सकता हूं, और यह सब अच्छा है, लेकिन जब मैं एप्लिकेशन शुरू करता हूं (एसडीके 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)। पूर्वावलोकन में काम करने का कारण यह संभावना है क्योंकि आप पूर्वावलोकन कर रहे हैं कि यह बड़े स्क्रीन पर कैसा दिखेगा।

मैं मान रहा हूँ कि आपने ऐसा किया है क्योंकि अन्यथा फ्रेमलैट सिर्फ एक दूसरे के ऊपर सभी विचारों को रखता है। आप अपने UI का उपयोग का निर्माण करके इस का समाधान कर सकता ConstraintLayoutहै, या के कुछ संयोजन RelativeLayoutऔर LinearLayout। विचारों को एक-दूसरे और स्क्रीन के सापेक्ष रखें, न कि बड़े फिक्स्ड ऑफ़सेट पर।