小编cod*_*Cat的帖子

Android:如何以编程方式设置布局的大小

作为Android应用程序的一部分,我正在构建一个按钮集.这些按钮是嵌套的LinearLayouts集的一部分.使用权重我根据包含父LinearLayout的大小自动调整自身大小.该想法是,基于屏幕的像素数和密度,将包含布局的大小设置为多个像素; 并根据该更改让按钮设置自行调整大小.

那么问题是:如何调整布局大小.

我已经尝试了几种建议的技术,没有一种能够接近工作.以下是构建按钮集的XML的子集:

    <LinearLayout android:layout_height="104pt" android:id="@+id/numberPadLayout" android:orientation="horizontal" android:layout_width="104pt"
    android:background="#a0a0a0"
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"
>

    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="1" android:id="@+id/button1" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="4" android:id="@+id/button4" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="7" android:id="@+id/button7" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="-" android:id="@+id/buttonDash" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>
    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout2" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="2" android:id="@+id/button2" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="5" android:id="@+id/button5" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="8" android:id="@+id/button8" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="0" android:id="@+id/button0" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>

    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout3" android:orientation="vertical" …
Run Code Online (Sandbox Code Playgroud)

layout android resize android-linearlayout

133
推荐指数
3
解决办法
25万
查看次数

Android - 单选按钮不显示其文本

我的应用程序有一个单选按钮组作为RelativeLayout的一部分.我的问题是RadioButtons没有显示他们的文字.我得到的只是按钮本身.

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/setupTabLayout"
    android:scaleType="fitXY"
    android:background="#ffffff" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:baselineAligned="true" 
    android:orientation="vertical">

    <TextView android:id="@+id/textView1" 
        android:text="Total Points" 
        android:textColor="#000000"
        android:textSize = "30sp"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:paddingBottom="5px"
        android:layout_gravity="top"
        android:layout_alignParentLeft="true"
        ></TextView>

      <EditText android:id="@+id/editTextTotal" 
        android:text="" 
        android:digits="-0123456789."
        android:windowSoftInputMode="stateVisible"
        android:focusable="true"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignTop="@+id/textView1" 
        android:layout_alignBottom="@+id/textView1"
        android:layout_toRightOf="@+id/textView1" 
    ></EditText>

    <RadioGroup android:id="@+id/radioGroup1"  
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:layout_alignParentLeft="true"
        android:layout_above="@+id/textView2"
    > 

        <RadioButton android:id="@+id/radioButton1" 
            android:checked="true" 
            android:text="Points" 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"  
        ></RadioButton>

        <RadioButton android:id="@+id/radioButton2" 
            android:text="Points" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content"
            android:layout_toRightOf="@+id/radioButton1" 
        ></RadioButton>

    </RadioGroup>   

    <TextView android:id="@+id/textView2" 
        android:text="Points Per = " 
        android:textColor="#000000"
        android:textSize = "30sp"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:paddingBottom="5px"
        android:layout_above="@+id/numberPadLayoutContainer"
        android:layout_alignParentLeft="true"
    ></TextView>

    <EditText android:id="@+id/editTextPoints" …
Run Code Online (Sandbox Code Playgroud)

xml android text radio-button

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

Raspberry Pi GPIO上的多个传感器

我正在为我的PI制作一个传感器包.我已经添加了Sparkfun的TMP102温度传感器.在GPIO上,它由引脚1供电,在引脚6上接地,引脚3和5处理串行数据.我写了一个python脚本来读取数据,一切正常.

我的问题是我现在想在GPIO上添加第二个传感器,BMP085压力传感器也在Sparkfun的分线板上.我发现的接线示例表明它需要挂接到与TMP102相同的GPIO引脚.它们都应该注册为串行设备,但我不确定如何将所有内容连接在一起.

我是一个内心的程序员,所以连接电子产品让人感到紧张.:-)

任何建议将不胜感激.

谢谢.

sensor gpio raspberry-pi

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

Android - 如何在制表符切换后更新显示?

我有一个带TabHost和三个标签的应用程序.他是我如何创建每个标签的示例:

    intent = new Intent().setClass(this, Setup.class); //intent.getClass()
    spec = tabHost.newTabSpec("setup").setIndicator("",
                    res.getDrawable(R.drawable.tab_setup))
                    .setContent(intent);
    tabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)

我的目标是,当您切换到新选项卡时,调用方法更新该选项卡上显示的信息.

这是一个问题:标签如何知道它已被显示?

tabs android android-intent android-tabhost

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

RaspiStill - 质量/尺寸小姐匹配 - 文件太大了

使用RaspiStill通过python进程shell使用JPG编码拍照.我得到一个超过两兆的文件.当我将质量降低到50%时,所拍摄照片的文件大小仅下降约200K,或者低于10%.当我使用原始的2 meg +文件并通过Paint.Net保存它,质量设置为85%时,它将文件大小降低到300k,或几乎减少90%.

我做错了什么,或者RaspiStill中的编码器有问题吗?

下面是我用来拍照的命令行:pi @ raspberrypi ~/Development/tests $ raspistill -n -t 100 -q 50 -e jpg -o fullsizejpgsethalfquality.jpg

产生的文件大小:2052kb通过Paint.Net以85%的质量重新保存相同的文件:319kb

思考?

python camera jpeg raspberry-pi

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

Android:如何确定文本长度(以像素为单位)?

我正在构建一个应用程序,并根据内容和屏幕大小,我想动态设置字体大小,以填充整个屏幕.

有没有办法确定文本行的宽度(以像素为单位)?我想避免试用和错误可以呈现给用户的闪烁.可以在没有首先显示TextView的情况下完成吗?

fonts android pixels width textview

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