小编Dal*_*ler的帖子

RelativeLayout重量

在布局资源XML中,我有3个RelativeLayout(s),它们位于主RelativeLayout中.视图将垂直显示.这三个RelativeLayout()彼此相邻设置,我想让它们填满整个屏幕,无论屏幕大小是多少.我的布局视图:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backg"
 >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="@dimen/top_mr_image"
    android:src="@drawable/temp" />

<RelativeLayout
    android:id="@+id/r1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/imageView1"
    android:layout_marginLeft="10dp"
    android:background="@drawable/r1bg"
    android:layout_weight="1"

     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="@dimen/txt_mr_right"
        android:layout_marginRight="@dimen/txt_mr_right"
        android:layout_marginTop="39dp"
        android:text="S"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView1"
        android:layout_marginLeft="@dimen/txt_mr_right"
        android:layout_marginRight="@dimen/txt_mr_right"
        android:text="T"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

    <RelativeLayout
        android:id="@+id/r2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@+id/r1"
        android:layout_toRightOf="@+id/r1"
        android:layout_weight="1" >
    </RelativeLayout>

            <RelativeLayout
        android:id="@+id/r3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@+id/r2"
        android:layout_toRightOf="@+id/r2"
        android:layout_weight="1" >

    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我设置weight=1layout_width=0dp为每个relativeLayout和这个技术使用按钮,我认为相同的将是relativeLayout,似乎我的想法是错误的.任何的想法?

UPD1:我添加了一张我想要的图像

在此输入图像描述

android android-layout

20
推荐指数
2
解决办法
7万
查看次数

Soundpool只播放文件的前5秒.为什么?

我在我的应用程序中使用Soundpool,到目前为止它运行良好,但我确实有一个10秒的wav文件.不幸的是,soundpool只播放前5秒.如何让soundpool播放整首曲目?我已经将wav转换为 - ogg和mp3仍然是同样的问题.它只播放前5秒.任何帮助将非常感激.

//set up audio player
mSoundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
//load fx
mSoundPoolMap.put(RAW_1_1, mSoundPool.load(this, R.raw.loop1, 1));
//playing soundpool
case R.id.button1:          
mSoundPool.stop(mStream1);
mStream1= mSoundPool.play(mSoundPoolMap.get(RAW_1_1), streamVolume, streamVolume, 1, LOOP_1_TIME, 1f);
Run Code Online (Sandbox Code Playgroud)

UPD Last:也许有人会在这里找到并阅读它.似乎soundpool不能播放超过5秒.这是他的最大值,因为更长的声音使用MediaPlayer.我希望你不会像我那样花那么多时间)

android soundpool

19
推荐指数
3
解决办法
1万
查看次数

当我调用cancel时,timer.scheduleAtFixedRate不会停止

在onCreate,我运行一个每分钟都重复的任务.我在这里是怎么做到的:

myTimer = new Timer();
    int delay = 30000;   // delay for 30 sec.
    int period = 600000;  // repeat every 60 sec.
    doThis = new TimerTask() {
      public void run() {

                     Log.v("TImer","repeated");
                     wv.reload();

      }
    };

    myTimer.scheduleAtFixedRate(doThis, delay, period);
Run Code Online (Sandbox Code Playgroud)

所有代码都在onCreate中.因此,当应用程序从屏幕上关闭时,我可以在logcat中看到计时器钢块运行,并且除非应用程序被销毁,否则不会停止.所以,在onPause我打电话的活动中,myTimer.cancel();但它没有帮助.即使应用程序不在屏幕上,我仍然可以在logcat中看到更新.那么,如何阻止timerTask

java android timertask

6
推荐指数
1
解决办法
1万
查看次数

从资源中加载和播放声音池

我有一堆声音,分配给一组按钮,我需要播放它们。我的所有声音都在资产文件夹中。然而,它不起作用。目的是: 从 assetFodler 加载并播放声音。我将从我的项目中拿出代码示例:

//set up  audio player
    mSoundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

 //getting files lists from asset folder
    aMan = this.getAssets();
    try {
        filelist = aMan.list("");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

为了避免使用大量代码行,我创建了一个加载播放声音的基本过程:

public void loadSound (String strSound, int stream) {

    try {
        stream= mSoundPool.load(aMan.openFd(strSound), 1);
    } catch (IOException e) {
        // TODO Auto-generated catch …
Run Code Online (Sandbox Code Playgroud)

android soundpool

5
推荐指数
1
解决办法
6585
查看次数

在对话框中仅与Facebook和Twitter应用程序共享按钮

我想在我的应用程序中添加共享按钮,并且我已完成以下操作:

final Intent shareIntent = new Intent(Intent.ACTION_SEND);              
            /* Fill it with Data */
            shareIntent.setType("plain/text");
            shareIntent.putExtra(Intent.EXTRA_TEXT, "www.somesite.com");    


            /* Send it off to the Activity-Chooser */
            startActivity(Intent.createChooser(shareIntent, "Share..."));
Run Code Online (Sandbox Code Playgroud)

它显示了一个对话框,我在这个对话框中看不到facebook和twitter.我确实在手机中安装了这两个应用程序.所以,first问题是为什么它不显示它们?而且second如果以后我会让他们莫名其妙地出现在手机上,如何使对话框只显示Facebook和Twitter,并且如果用户没有他们,让用户只需通过提供链接到官方应用程序进行安装.

android

4
推荐指数
1
解决办法
5769
查看次数

随机选择int数

我有以下代码来获取随机int数字

for (int i=1;i<=5;i++) {
  int rand= new Random().nextInt(10);
  Log.d("Ramdom number", String.valueOf(rand));
}
Run Code Online (Sandbox Code Playgroud)

问题是我不想重复随机数,这意味着当我运行这个代码时,它给了我5个数字,但其中两个至少重复.有什么建议?

java android

3
推荐指数
1
解决办法
415
查看次数

单击按钮时模拟延迟

我有一个按钮,当点击这个按钮时,我想做一些动作并将它们还原,让我们说5秒钟.例如,当单击按钮A时,TextA.Text变为"Clicked"5秒,在5秒内文本的值将恢复为原始值.我在这里有什么,但我觉得这是完全错误的方式.延迟的代码:

diff=time2-time1;

            while (diff<5000) {
                //Log.d("Timer is", String.valueOf(diff));
                time2=System.currentTimeMillis();
                diff=time2-time1;
            }
Run Code Online (Sandbox Code Playgroud)

所以直到循环正在模拟延迟并在我做我想要的之后.有什么建议?

java android

1
推荐指数
1
解决办法
1177
查看次数

标签 统计

android ×7

java ×3

soundpool ×2

android-layout ×1

timertask ×1