小编Mar*_*Tan的帖子

Setprecision令人困惑

我只是想问一下setprecision,因为我有点困惑.

这是代码:

#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
  double rate = x;
  cout << fixed << setprecision(2) << rate;
}
Run Code Online (Sandbox Code Playgroud)

其中x =以下:

等式的左边是x的值.

1.105 = 1.10应为1.11

1.115 = 1.11应为1.12

1.125 = 1.12应为1.13

1.135 = 1.14这是正确的

1.145 = 1.15也正确

但如果x是:

2.115 = 2.12这是正确的

2.125 = 2.12应为2.13

那么为什么在某个值上它是正确的但有时它是错的?

请赐教.谢谢

c++

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

我们如何在R.id中使用变量

xml的内容是

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<AbsoluteLayout
    android:id="@+id/AbsoluteLayout1"
    android:layout_width="match_parent"
    android:layout_height="172dp"
    android:layout_x="12dp"
    android:layout_y="26dp"
    android:visibility="invisible" >

</AbsoluteLayout>

  <AbsoluteLayout
    android:id="@+id/AbsoluteLayout2"
    android:layout_width="match_parent"
    android:layout_height="172dp"
    android:layout_x="20dp"
    android:layout_y="184dp" android:visibility="invisible">

</AbsoluteLayout>

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

这是主要代码

String layoutid;
int ctr = 1;
AbsoluteLayout [] mainlayout = new AbsoluteLayout[12];

   while (ctr<3)
   {
        layoutid = "AbsoluteLayout" + ctr;
        mainlayout[ctr] = (AbsoluteLayout)findViewById(R.id.layoutid);
        ctr++;
   }
Run Code Online (Sandbox Code Playgroud)

我们需要制作一个循环

 ctr = 1 
 AbsoluteLayout + ctr = AbsoluteLayout1 
 ctr++; 

 AbsoluteLayout + ctr = AbsoluteLayout2
Run Code Online (Sandbox Code Playgroud)

我们要声明AbsoluteLayout1和AbsouluteLayout2,但它不起作用.我们知道R.id.layoutid是罪魁祸首.那我们怎么解决呢?

android absolutelayout

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

button.setColorFilter不工作

我有一个代码,可以在单击时更改图像按钮的色调.

这是java代码

 button.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent me) 
        {
            if (me.getAction() == MotionEvent.ACTION_DOWN) 
            {

                button.setColorFilter(Color.argb(150, 155, 155, 155));

            } 

            else if (me.getAction() == MotionEvent.ACTION_UP) 

            {
                button.setColorFilter(Color.argb(0, 155, 155, 155)); 
                }
            return false;
        }

    });
Run Code Online (Sandbox Code Playgroud)

代码在这个xml上工作正常,点击时按钮变暗.

  <ImageButton
    android:id="@+id/schedule"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="138dp"
    android:layout_y="169dp"
    android:src="@drawable/schedule"
    />
Run Code Online (Sandbox Code Playgroud)

但它没有在这个xml上工作,点击时按钮不会变暗.

  <ImageButton
    android:id="@+id/schedule"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="138dp"
    android:layout_y="169dp"
    android:background="@drawable/schedule"
    />
Run Code Online (Sandbox Code Playgroud)

为什么我使用android:background setColorFilter不起作用?但如果我使用android:src它工作正常.

android imagebutton

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

标签 统计

android ×2

absolutelayout ×1

c++ ×1

imagebutton ×1