我需要知道是否有一个实例,在此onResume之前onCreate调用至少一次.谢谢.
编辑:从活动生命周期来看,它似乎并非如此.但我想仔细检查一下.
有没有办法将输入的文本置于EditText字段中心?更具体地说,代替从框左侧开始的光标,它应该从中心开始并向左移动,因为它填充了输入.
我的main.xml文件中有一个ImageView:
<ImageView
android:id="@+id/pageImage"
android:layout_width="270dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/pageimage" />
Run Code Online (Sandbox Code Playgroud)
我只需要以layout_height编程方式将其设置为另一个值.
另外,我需要在dp中设置值.所以它目前是45dp,我想在主要活动中将其更改为另一个值.
我试图用LayoutParams弄清楚如何做到这一点,但我无法成功.
谢谢.
假设我的String格式如下:
2.2
我想用空格替换小数点,使它看起来像这样:
22
我该怎么做呢?我认为replace可以做到这一点,但当我这样尝试时:
string.replace('.', '');
我得到一个错误,''因为它应该不是一个字符.这是有道理的,那么我怎么能完成我想要的呢?
这是我的功能打开串口(使用Ubuntu 12.04):
int open_port(void)
{
int fd; /* File descriptor for the port */
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
// Could not open the port.
perror("open_port: Unable to open /dev/ttyUSB0 - ");
}
else
fcntl(fd, F_SETFL, 0);
struct termios options;
tcgetattr(fd, &options);
//setting baud rates and stuff
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
options.c_cflag |= (CLOCAL | CREAD);
tcsetattr(fd, TCSANOW, &options);
tcsetattr(fd, TCSAFLUSH, &options);
options.c_cflag &= ~PARENB;//next 4 lines setting 8N1
options.c_cflag &= ~CSTOPB; …Run Code Online (Sandbox Code Playgroud) 刚开始研究OpenCV for Android.我注意到在运行使用它的应用程序之前,我需要安装一个名为OpenCV Manager的东西.
有没有办法将此经理与我的应用程序捆绑在一起,以便用户不必单独安装它?如果可能的话,这真的会有所帮助.
我还没有编写过使用OpenCV的应用程序,但我只是展望未来.
非常感谢.
在我的布局XML文件中,我通过一个名为的单独文件引用了很多参数dimens.xml.
例如,dimens.xml包含以下参数:
<dimen name="textSize_normal">20dp</dimen>
<dimen name="buttonTextSize_normal">15dp</dimen>
<dimen name="editTextSize_normal">17dp</dimen>
<dimen name="buttonHeight_normal">37dp</dimen>
<dimen name="margin_normal">5dp</dimen>
Run Code Online (Sandbox Code Playgroud)
main.xml例如,在我的内容中,我会TextView通过执行以下操作来设置文本大小:
android:textSize="@dimen/editTextSize_normal"
Run Code Online (Sandbox Code Playgroud)
它很棒.
现在,我的问题是,是否可以从我的主要活动以编程方式设置dimen我的dimen.xml文件中的变量值?我想要做的是获取屏幕尺寸,并设置,例如,textSize基于屏幕高度的一小部分,以便它可以很容易地适应任何屏幕尺寸.我已经弄明白了,我只需要你的帮助来弄清楚如何dimen在我的代码中设置变量.
我在一周前将我的应用程序部署到Google Play,并经常检查我的开发者控制台以分析统计信息.问题是,有时它甚至在24小时后也不会更新.例如,我的控制台中的任何数字都已经改变了两天,这变得非常令人沮丧.
这是正常的吗?有什么建议?谢谢.
我的Android应用程序的主要活动如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:paddingLeft="60dp"
android:paddingTop="53dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/billAmountText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/billAmount_string"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/billAmount"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="@id/billAmountText"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
为了确保键盘弹出时背景图像(在第一个RelativeLayout中定义)不会被挤压,我已android:windowSoftInputMode="stateVisible|adjustPan在清单文件中设置了我的活动.现在所有的背景和布局都很好,没有任何调整大小.
但问题是我的ScrollView现在不能正常工作,因为我认为由于我对清单的上述修改,系统认为窗口不需要调整大小 - 所以ScrollView没有被激活.当我android:windowSoftInputMode="stateVisible|adjustPan拿出滚动工作时会发生相反的情况,但是当键盘弹出时背景会被挤压.
有没有办法对它进行编码,这样我的背景就不会受到挤压,我的ScrollView仍然有效?谢谢!
我正在遵循将SoundPool集成到我的应用程序中的教程,这是该教程中给出的代码:
package com.example.soundpoolexample;
import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class SoundPoolExample extends Activity implements OnTouchListener {
private SoundPool soundPool;
private int soundID;
boolean loaded = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View view = findViewById(R.id.textView1);
view.setOnTouchListener(this);
// Set the hardware buttons to control the music
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
// Load the sound
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, …Run Code Online (Sandbox Code Playgroud)