我正在使用Android中的一个Button遇到奇怪的行为.
我创建了一个自定义按钮(MyButton),我在其上放了一些方法来扩展deafult View,比如添加一个禁用/启用方法来更改按钮.
这是MyButton的代码:
public class MyButton extends Button {
/** Enabled. */
private boolean enabled = true;
/** The default bg. */
private Drawable defaultBG = null;
/** The disabled drawable. */
private int disabledDrawable = 0;
/******************/
/** CONSTRUCTORS **/
/** [...] **/
/******************/
/**
* Disable.
*/
public void disable()
{
this.setClickable(false);
this.setFocusable(false);
Log.d("MY_BUTTON", "DISABLED!!");
if(!enabled || disabledDrawable == 0)
return;
defaultBG = this.getBackground();
this.setBackgroundResource(disabledDrawable);
enabled = false;
}
/**
* Enable.
*/
public void enable()
{ …Run Code Online (Sandbox Code Playgroud) 我想从视图(android.view.View)中删除基于codition.view的图像视图是该图像视图的src.如何从视图中删除imageView.请帮忙
当我仅在水平轴上捏时,我需要放大我的视图.我ScaleGestureDetector.getCurrentSpanX()在我的代码中实现了.从API doc开始它的作用是:
Return the average X distance between each of the pointers forming the gesture in progress through the focal point.
但仅适用于API级别11或更高级别.此类中的其他一些类似方法也需要API级别11:
getCurrentSpanX ()
getCurrentSpanY ()
getPreviousSpanX ()
getPreviousSpanY ()
Run Code Online (Sandbox Code Playgroud) 我需要在列表视图中设置一个偏移量。我最初是使用ScrollBy(X,Y)实现的,但是一旦我触摸列表视图,它就会恢复为零(我的偏移量为负)。
如何保持此偏移量?
嗯,这是我在任何地方都找不到的东西。它可能写在某个地方,但我的可能是由于我的搜索技巧不佳而无法找到它。
所以基本上我想要做的是,我想创建一个类,我在其中传递字符串数组,并且从该数组中,该类将返回一个视图,其中按钮的数量作为字符串数组中元素的数量。
就像是,
Public class customView extends View {
public customView(Context context, AttributeSet attrs, String[] array) {
super(context, attrs, array);
}
}
Run Code Online (Sandbox Code Playgroud)
但我无法做到这一点。因为 View 类在构造函数参数中不支持 String 数组。有没有人对此有任何解决方案?我应该采取任何新方法来实现这一目标吗?
谢谢,
杰·斯泰平。
我在onCreateView()Fragment中夸大了版面。此布局包含一个自定义视图。现在文档的onActivityCreated()说,这是“ 片段的活动已创建时调用这个片段的视图层次实例化 ”。这意味着布局已膨胀,并且布局中的视图之前已创建onActivityCreated()。
那么,这是否意味着视图的onLayout(),onSizeChanged()和onDraw()方法之前调用onActivityCreated()?
android ondraw android-fragments android-canvas android-view
我正在尝试在我的 Android 应用程序中实现按钮点击处理。
在包含我的按钮的 XML 布局文件中,我向我的ButtonXML 元素添加了以下行:
android:onClick="handleClick"
Run Code Online (Sandbox Code Playgroud)
我还在Activity使用此布局的 中定义了具有以下签名的方法:
public void handleClick() { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
但是,当我使用此代码运行我的应用程序时,它崩溃了。我能够通过将我的方法签名更新为以下内容来修复此崩溃:
public void handleClick(View v) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么我需要包含这个View参数?
我有一个视图SubEpoxyRecyclerView,它是EpoxyRecyclerView我的父类的子类。当初始化此视图时,超类调用构造函数主体中的EpoxyRecyclerView方法。setItemSpacingPx(Int)
当调用这个方法时,我的类变量都没有被初始化!应用程序在线崩溃,itemDecorator.pxBetweenItems指出该 itemDecorator值为空,这是不可能的
子类(科特林):
class SubEpoxyRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: EpoxyRecyclerView(context, attrs, defStyleAttr) {
private val itemDecorator: Decor = Decor()
private val someInt: Int = 5
private var someBoolean: Boolean = true
override fun setItemSpacingPx(spacingPx: Int) {
// Called from superclass. Debug: itemDecorator is null,
// someInt is 0, someBoolean is false
removeItemDecoration(itemDecorator)
itemDecorator.pxBetweenItems = spacingPx
if (spacingPx > 0) {
addItemDecoration(itemDecorator) …Run Code Online (Sandbox Code Playgroud) 我想查一下!例如 - if(tv.Visible == true)then showMessage("Yee it is Visible")else("It not visible"); 我希望你明白!
我的客户想要一个像这样的菱形进度:
我的第一次尝试是使用图书馆,但我找不到存在的图书馆
我的下一个尝试是学习如何使用ProgressBarandroid 附带的视图,并使用这个答案(最接近堆栈溢出的答案)设置我自己的可绘制对象,但该答案仅适用于ring形状,而不适用于矩形。
创建菱形进度视图的最佳方法是什么?(无论如何:自定义视图,progressDrawable)我该怎么做?
app:layout_goneMarginLeft及其变体如何影响约束布局中的视图排列?
android android-layout android-view android-studio android-constraintlayout
我有两个不同的活动,我想在另一个活动中同时显示它们.有没有办法做到这一点?
提前致谢!
android android-layout android-fragments android-view android-activity