我有一个RelativeLayout我已经设置了背景的drawable. 我能够RelativeLayout在RadioButton检查时将背景更改为另一个背景。但是当它改变时我如何给它一个动画?
代码:activity_main.xml:
<RelativeLayout
android:layout_width="80dp"
android:layout_height="50dp"
android:gravity="center"
android:background="@drawable/original"
android:id="@+id/rel1">
<RadioButton
android:id="@+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
原始.xml(可绘制):
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#ffffff">
</solid>
<corners
android:radius="50dp">
</corners>
</shape>
Run Code Online (Sandbox Code Playgroud)
按下.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#2196F3">
</solid>
<corners
android:radius="50dp">
</corners>
</shape>
Run Code Online (Sandbox Code Playgroud)
Java类:
radio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
relativeLayout.setBackgroundResource(R.drawable.pressed);
}
}
});
Run Code Online (Sandbox Code Playgroud) animation android android-animation android-layout android-view
我是RxJava的新手,我想我可能会忽略一些非常基本的东西.所以我创建了Observable一个像这样执行长时间运行的I/O任务.现在我想确保订阅者在Android UI线程上收到其结果:
Observable.create(new ObservableOnSubscribe<Device>() {
@Override
public void subscribe(@io.reactivex.annotations.NonNull final ObservableEmitter<Device> e) throws Exception {
//Long running task
}
}).subscribeOn(Schedulers.io())
Run Code Online (Sandbox Code Playgroud)
如您所见,我已执行了长时间运行的任务Schedulers.io().如何切换回Android UI线程?
所以我有一个非常基本的 RxJava 观察者流工作流程,我从改造中请求一些东西,如果响应成功,我会烘烤成功的消息,如果出现错误,我会烘烤错误消息。
我下面提到的情况是错误情况,我期望来自 API 的错误消息,我将其转换为用户可读的单词并显示为Toast,如下所示,当我使用doOnNext这种doOnError方式时,它会因提到的错误而崩溃。
我throwExceptionIfFailure还添加了方法,它显示了如何转换可读消息以及控制台指向错误的行。
registerNFCTag(body)
.map(result -> throwExceptionIfFailure(result))
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(result -> {
toggleLoaders(true);
appToast(getString(R.string.done_msg) + tagName);
})
.doOnError(throwable -> {
Toasty.error(this, throwable.getLocalizedMessage()).show();
toggleLoaders(true);
})
.subscribeOn(Schedulers.io())
.subscribe();
Run Code Online (Sandbox Code Playgroud)
错误如果这还不够,我也可以发布堆栈跟踪。
java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling.
Run Code Online (Sandbox Code Playgroud)
ThrowExceptionIfFailure 方法。
public <T> T throwExceptionIfFailure(T res) {
Response result = (Response<?>) res;
if (!result.isSuccessful()) {
try {
String msg = result.errorBody().string();
Log.d(TAG, "throwExceptionIfFailure: "+msg);
if (result.code() == 401 || result.code() == 403) …Run Code Online (Sandbox Code Playgroud) 我将菜单抽屉用作清单,并且 onDrawerClosed 根据 int 值将向用户收费或不保存更改。但是 onDrawerClosed 方法调用了两次,一次使用 int 和正确的值,一次使用 int 和值 0?这导致我的程序同时调用 if 和 else 语句,以便保存更改并提示他们付款。
//Used so that when drawer closed banned list saves
public void drawerListener(){
mDrawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
customAdaptor.clearJustChanged();
}
@Override
public void onDrawerClosed(View drawerView) {
System.out.println("Cost of Changes:" + customAdaptor.getUserCostOfChange());
if (customAdaptor.getUserCostOfChange() > 0) {
getBuyAlert(customAdaptor.getUserCostOfChange());
customAdaptor.setUserCostOfChange(0);
}
else {
bannedList = customAdaptor.getBannedList();
databaseReference.child("BannedApps").setValue(bannedList);
}
}
@Override
public void onDrawerStateChanged(int newState) …Run Code Online (Sandbox Code Playgroud) 我想创建一个completable并在后台线程中运行它,但它不是打电话Action的run()时候,我就订阅Schedulers.io()
基本上我想通过RxAndroid执行以下操作:
Thread t = new Thread(new Runnable() {
public void run() {
doSomething();
}
});
t.start();
Run Code Online (Sandbox Code Playgroud)
使用RxAndroid,我正在执行以下操作:
Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
doSomething();
}
}).subscribeOn(Schedulers.io());
Run Code Online (Sandbox Code Playgroud)
它的run()方法是没有得到所谓的如果我这样做Schedulers.io(),但如果我这样做会被调用subscribe()。
订阅时,我找不到它为什么运行Schedulers.io()。
所以我研究了很多,有很多问题和答案谈论按钮和颜色.但在你投票之前看到这个问题更具体,更实际,我没有找到答案.
我正在使用元素Button作为我的xml布局.来自android.widget的Button类,它扩展了TextView.
此视图可以通过java代码标记为启用或禁用..setEnabled(true|false).
按钮xml代码
<Button
android:id="@+id/maps_list_save_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/str_save"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Run Code Online (Sandbox Code Playgroud)
我想要的是什么:
我不想做的事:
创建一个新元素并包含布局,我正在避免这个,因为我想保留选定的动画,提升,填充,提升等.再创建一切并不聪明.
我已经尝试过:
更改背景 =它松开内部填充,什么使按钮更大,我想保持材料设计"规则"


更改主题 =我尝试通过编辑器和代码更改主题,但发生了两件事:或者我更改了不是按钮的更多内容,或者我更改了相同颜色的启用和禁用.
即使在寻找文档,我也没有找到如何正确使用这个元素.
android android-theme android-button android-view android-styles
我buttonViews在垂直线性布局中有 3 个视图 ( )的活动。我正在动态生成(膨胀)这些视图。我想应用一个动画,以便在活动开始时,第一个按钮滑入 -> 100 毫秒延迟 -> 第二个按钮滑入 -> 100 毫秒延迟 -> 第三个按钮滑入。
试图
我尝试以这种方式实现它:
private void setMainButtons() {
ArrayList<String> dashboardTitles = DashboardUtils.getDashboardTitles();
ArrayList<Integer> dashboardIcons = DashboardUtils.getDashboardIcons();
final ViewGroup root = findViewById(R.id.button_container);
for (int i = 0; i < (dashboardTitles.size() < dashboardIcons.size() ? dashboardTitles.size() : dashboardIcons.size()); i++){
final View buttonView = DashboardButtonInflater.getDashboardButton(root, dashboardTitles.get(i), dashboardIcons.get(i), this);
if (buttonView == null) continue;
buttonView.setOnClickListener(this);
root.addView(buttonView);
animateBottomToTop(buttonView, (long) (i*50)); // Calling method to animate buttonView
}
}
//The function that …Run Code Online (Sandbox Code Playgroud) animation android android-animation android-layout android-view
我有一个非常奇怪的错误,因为它仅在从generate安装应用程序之后发生.apk。当我尝试通过IDE运行该应用程序时,它运行良好。
java.lang.IllegalAccessError: Method 'int <package>.BaseActivity$Companion.getANIMATION_SLIDE_FROM_RIGHT()' is inaccessible to class '<package>.MyActivity' (declaration of '<package>.MyActivity' appears in /data/app/<package>-mg7eYmJ8hX5WvkNWNZWMVg==/base.apk!classes3.dex)
Run Code Online (Sandbox Code Playgroud)
如您所见,有一个名为的类BaseActivity,看起来像这样:
open class BaseActivity : AppCompatActivity() {
companion object {
@JvmStatic
protected val ANIMATION_DEFAULT = 0
@JvmStatic
protected val ANIMATION_SLIDE_FROM_RIGHT = 1
@JvmStatic
protected val ANIMATION_SLIDE_FROM_BOTTOM = 2
}
protected open var animationKind = ANIMATION_DEFAULT
// Some other stuff
}
Run Code Online (Sandbox Code Playgroud)
现在,每个活动都扩展了该类,并经常覆盖animationKind如下内容:
class MyActivity: BaseActivity() {
override var animationKind = ANIMATION_SLIDE_FROM_RIGHT
// Some other stuff
}
Run Code Online (Sandbox Code Playgroud)
问题是,ANIMATION_SLIDE_FROM_RIGHT是无法访问 …
经过一些工作,我的路线应用程序工作正常.我唯一想要添加的是双击放大功能,但我不知道如何.
你能给我一个暗示吗?
java android android-view android-mapview android-touch-event
我正在研究Dagger 2库并遇到了传递参数的问题,这些参数无法从"extends Application"类中获得.
例如,我需要传递FragmentManager给ViewPager适配器构造函数.你会怎么做?
我的应用程序:
public class MyApplication extends Application {
private MyAppComponent mMyAppComponent;
@Override
public void onCreate() {
super.onCreate();
Context context = getApplicationContext();
mMyAppComponent= DaggerMyAppComponent.builder()
.utilityModule(new UtilityModule())
.locationModule(new LocationModule(context))
.appModule(new AppModule(context))
.pagerAdapterModule(new PagerAdapterModule(context)) //this one is problematic
.build();
}
public MyAppComponent getmMyAppComponent() {
return mMyAppComponent;
}
}
Run Code Online (Sandbox Code Playgroud)
MyAppComponent:
@Singleton
@Component(
modules = {
UtilityModule.class,
LocationModule.class,
PagerAdapterModule.class,
AppModule.class
}
Run Code Online (Sandbox Code Playgroud)
)
public interface MyComponent {
FragmentManager fragmentManager(); //is it right?
public void inject(NavigationActivity navigationActivity);
} …Run Code Online (Sandbox Code Playgroud) android ×10
android-view ×5
java ×4
rx-android ×3
animation ×2
rx-java ×2
rx-java2 ×2
dagger ×1
dagger-2 ×1
drawerlayout ×1
jvm ×1
kotlin ×1
listener ×1