小编Ben*_*ett的帖子

为什么我不能覆盖Android项目中包含的布局的布局属性?

我正在尝试创建一些模块化的UI元素,如Android开发人员所述 - 创建可重用的UI组件,遗憾的是我没有得到所需的结果.文章指出:

您可以覆盖所有布局参数.这意味着任何android:layout_*属性都可以与标记一起使用.

我的XML代码看起来像这样(相关部分):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

<include android:id="@+id/radio_group"
         layout="@layout/radio_buttons"
         android:layout_marginTop="75dp"
        />

<include android:id="@+id/player_group"
         layout="@layout/player_buttons"
         android:layout_alignParentBottom="true"
        />


<EditText android:id="@+id/text_field"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Enter Your Login ID:"
    android:layout_below="@id/player_group"
    />
Run Code Online (Sandbox Code Playgroud)

这是第一个包含的布局:

<RadioGroup
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/radio_group"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginBottom="20dp"
    >

<RadioButton android:id="@+id/radio01"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Song #1"
             android:paddingLeft="45dp"
        />

[two more identical buttons]

<TextView   android:id="@+id/choice"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="you have selected:"/>

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

和另外一个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<Button android:text="btn01"
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

layout android

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

ruby - 如何正确解析不同数量的命令行参数

n00b提问!这是问题:我正在创建一个至少需要3个参数的shell脚本:一个字符串,一个行号和至少一个文件.

我写了一个脚本,它将接受完全3个参数,但我不知道如何处理多个文件名参数.

这是我的代码的相关部分(跳过写回文件等):

#!/usr/bin/env ruby

the_string = ARGV[0] 
line_number = ARGV[1]
the_file = ARGV[2] 

def insert_script(str, line_n, file)
  f = file
  s = str
  ln = line_n.to_i

  if (File.file? f)
    read_in(f,ln,s)
  else 
    puts "false"
  end
end

def read_in(f,ln,s)
  lines = File.readlines(f)
  lines[ln] = s + "\n"
  return lines
end

# run it
puts insert_script(the_string, line_number, the_file)
Run Code Online (Sandbox Code Playgroud)

现在我知道编写一个可以遍历所有参数的块很容易:

ARGV.each do |a|
   puts a 
end
Run Code Online (Sandbox Code Playgroud)

但是我只需要将ARGV [2](第一个文件名)中的args循环到最后一个文件名.

我知道必须 - 至少 - 至少有一种简单的方法可以做到这一点,但我现在看不出它是什么!

在任何情况下 - 如果有人能指出我的教程或例子,我会非常高兴,我确信那里有很多 - 但我似乎无法找到它们.

谢谢

ruby command-line arguments

5
推荐指数
2
解决办法
5562
查看次数

如何打开和关闭自动亮度?(不重复)

我只是试图打开和关闭自动亮度.我开始使用此代码(在onCreate方法内)

final ToggleButton autoBrightToggle = (ToggleButton) findViewById(R.id.brightToggle);

    // display auto brightness state
    final ToggleButton autoBrightToggle = (ToggleButton) findViewById(R.id.autoToggle);
    autoOnOrOff.setText(String.valueOf(getAutoBrightnessMode()));

    autoBrightToggle.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (autoBrightToggle.isChecked()) {
                setAutoBright(true);
            } else {
                setAutoBright(false);
            }
        }
    }); // end anonymous OnClickListener function

    // toggle the brightness mode
    private void  setAutoBright(boolean mode) {
      if (mode) {
        Settings.System.putInt(cr, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        autoOnOrOff.setText(String.valueOf(getAutoBrightnessMode()));
      } else {
        Settings.System.putInt(cr, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
        autoOnOrOff.setText(String.valueOf(getAutoBrightnessMode()));
      }
    }
Run Code Online (Sandbox Code Playgroud)

哪个似乎不起作用.setAutoBrightnessMode()方法也在onResume()中再次调用,但具有相同的非结果.无论如何,如果有人觉得这个问题多余,我很抱歉,其他帖子没有让我到达我需要去的地方!

(FWIW - 我在我的旧Droid X和我的Galaxy Nexus上测试了这个,而不是模拟器)

编辑 - 更新:我现在99%确定我没有看到设置面板和桌面小部件中反映的自动亮度模式有任何变化 - 即使 …

settings android

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

标签 统计

android ×2

arguments ×1

command-line ×1

layout ×1

ruby ×1

settings ×1