我找不到一个如何做到这一点的好例子.
我有一个设置x高度的RelativeLayout.
我想添加一个按钮,将高度扩展到x + y高度.
有人可以通过编程方式向我介绍一个很好的例子吗?
在Android模拟器上,当我退出我的应用并立即再次运行时,我明白了
OutOfMemoryError: bitmap size exceeds VM budget.
Run Code Online (Sandbox Code Playgroud)
但在设备本身,这不会发生.为什么?
我正在尝试添加到我现有的statelist drawable,一个禁用状态,它只是不起作用.
最初,我有这个代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/store_item_background_selected" android:state_selected="true"/>
<item android:drawable="@drawable/store_item_background"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
它适用于选定而未选中.
现在我想添加android:state_enabled ="false",如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/store_item_background_selected" android:state_selected="true"/>
<item android:drawable="@drawable/store_item_background" android:state_enabled="true"/>
<item android:drawable="@drawable/store_item_background_disabled"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
它永远不会切换到禁用的图像.
有任何想法吗?
编辑
我添加setEnabled(false)到视图的构造函数中,我将此状态列表设置为drwable,现在我看到禁用的图像,但是一旦我将视图设置为启用,它就不会再次切换到禁用状态.
我想画一个透明的圆圈,但它不起作用.
当我绘制位图时,它可以工作,但圆圈不会变得透明.
这是我的简短代码:
Paint paint = new Paint();
paint.setAlpha(125);
canvas.drawBitmap(bitmap, sourceRect, destRect, paint); // this works fine
canvas.drawCircle(x, y, radius, paint); // the circle is drawn but not transparent
Run Code Online (Sandbox Code Playgroud) 我想定义一个布局,它的方向是水平的,但是如果子视图的宽度超过宽度,它会在新的行中添加新的子视图.
能做到吗?
我有一个非常奇怪的问题 - 我为进度条定义了一个自定义进度drawable
有时它显示,有时它不显示.
我尝试清理我的项目,重新启动eclipse甚至重新启动计算机.
它仍然发生.
这是进度可绘制的xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<gradient
android:startColor="#6f7754"
android:endColor="#858762"
android:angle="90"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<gradient
android:startColor="#ffba00"
android:endColor="#af6c03"
android:angle="90"/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp" />
<gradient
android:startColor="#ffba00"
android:endColor="#af6c03"
android:angle="90" />
</shape>
</clip>
Run Code Online (Sandbox Code Playgroud)
这是我使用它的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="2dp"
android:background="@drawable/quick_action_item_btn">
<ImageView
android:id="@+id/icon"
android:layout_width="21dp"
android:layout_height="21dp"
android:scaleType="centerInside"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="20dp"
android:layout_height="4dp"
android:layout_marginTop="2dp" …Run Code Online (Sandbox Code Playgroud) 我试图在内部存储上写一些文件.
我看到FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);的数据存储和我理解的是,文件将是私有的我的应用程序.
但问题是它只能打开一个没有路径的文件,所以首先我用file.mkdir()打开一个新的目录文件,但现在,我该如何将该文件写为私有?
我使用了一些我在滑动面板上找到的代码,基本上它可以工作但是有一个小问题.
第一次打开面板时动画不起作用.
这是动画的代码:
TranslateAnimation anim = null;
m_isOpen = !m_isOpen;
if (m_isOpen) {
setVisibility(View.VISIBLE);
anim = new TranslateAnimation(0.0f, 0.0f, getHeight(), 0.0f);
} else {
anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, getHeight());
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation animation) {
// not needed
}
public void onAnimationStart(Animation animation) {
// not needed
}
});
}
anim.setDuration(300);
anim.setInterpolator(new AccelerateInterpolator(1.0f));
startAnimation(anim);
Run Code Online (Sandbox Code Playgroud)
为什么在第一次打开面板时没有动画,但其他所有动画都有?
我为创建帐户活动设计了一个布局。
当一个人EditText失去焦点时,我会对输入进行一些检查,如果有什么不对的地方,我想重新集中注意力EditText。
我已经看到了一些关于此的问题,但它对我不起作用(或者我做错了什么)。
当我触摸触发 requestFocus() 的不同 EditText 时,焦点仍停留在当前焦点上EditText,另一个焦点图标显示在EditText请求焦点中。
请帮忙
这是我的布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.cellap.tq"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/create_account_background" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="70dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp">
<TextView
android:id="@+id/userTextView"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textColor="#F4DFA7"
android:layout_marginRight="5dp"
android:text="Username"
android:gravity="right"
android:layout_gravity="center_vertical"/>
<EditText
android:id="@+id/userEditText"
android:inputType="text|textEmailAddress"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:maxLength="64"
android:background="@drawable/edit_text"
android:layout_gravity="center_vertical|right"
android:textColor="@android:color/white">
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp">
<TextView
android:id="@+id/passTextView"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#F4DFA7"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="Password"/>
<EditText
android:id="@+id/passEditText"
android:layout_width="fill_parent" …Run Code Online (Sandbox Code Playgroud) android ×9
animation ×2
layout ×2
data-storage ×1
file ×1
focus ×1
java ×1
private ×1
progress-bar ×1
xml ×1