使用单选按钮在照片之间切换,并使用进度栏、文本视图和搜索栏更改所选照片的不透明度

guz6ccqo  于 2021-07-08  发布在  Java
关注(0)|答案(2)|浏览(493)

这个问题在这里已经有答案了

adb.exe已过时,存在严重的性能问题(21个答案)
上个月关门了。
我是一个今年学习android studio和java的学生。上周我学习了进度条、搜索条和单选按钮。我的作业是使用单选按钮在照片之间切换,并使用进度栏、文本视图(百分比)和搜索栏来更改所选照片的不透明度。
我尽我所能,实际上,当我看“设计”,我可以看到我的进度栏,搜索栏,和文本视图,一切都很好,但当我启动应用程序(在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>

下面是java:

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;
        }
    }

      }

设计照片:design app:app写这篇文章的时候,我收到了这个错误信息,所以我不知道它是否真的相关:问题信息

sq1bmfud

sq1bmfud1#

为什么不尝试更新到adb的更新版本(或者更新整个android工作室)。

xqk2d5yq

xqk2d5yq2#

你把这些都放进了一个 FrameLayout 有很大的固定利润。您丢失的视图可能是屏幕外的( android:layout_marginTop="625sp" 意味着你抵消了很多;另外,你应该使用 dp ). 它在预览中工作的原因很可能是因为您在更大的屏幕上预览它的外观。
我假设您这样做是因为framelayout会将所有视图放在彼此的顶部。您可以通过使用 ConstraintLayout ,或者 RelativeLayout 以及 LinearLayout . 相对于彼此和屏幕定位视图,而不是以较大的固定偏移。

相关问题