Android小工具布局 [英] Android Widget Layouts

查看:175
本文介绍了Android小工具布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力与创造Android的布局和我仍然在寻找一个非常坚实的教程,提供有用的例子。

目前,我想创建一个Widget是类似许多市场上现有的Andr​​oid窗口小部件。例如,包含在小部件(下一个图像)和普通文本上包含更多的信息,如预测的小部件的权的右侧的温度的简单天气部件。我有以下的code和我的形象无法正确加载。文本无法在小部件上加载也。有人能帮助引导我,让我至少可以看到的图像和一些文字:

 <?XML版本=1.0编码=UTF-8&GT?;<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /小工具
    机器人:layout_width =FILL_PARENT
    机器人:方向=横向
    机器人:背景=@绘制/ appwidget_bg
    机器人:layout_height =FILL_PARENT>    <的ImageButton
    机器人:ID =@ + ID / message_button
    机器人:layout_width =100px的
    机器人:layout_height =WRAP_CONTENT
    机器人:SRC =@绘制/邮件
    机器人:scaleType =fitXY
    />   < ImageView的
       机器人:ID =@ + ID /除法
       机器人:layout_width =1dip
       机器人:layout_height =match_parent
       机器人:背景=@绘制/ appwidget_divider
       机器人:layout_alignRight =@ + ID / message_button
       />
   <的TextView
        机器人:ID =@ + ID / current_kw
        机器人:layout_toRightOf =@ + ID /除法
        机器人:layout_width =80px
        机器人:layout_height =WRAP_CONTENT
        机器人:TEXTSIZE =18dp
        机器人:文字颜色=#FFFFFF
        机器人:字体=SANS
        机器人:文字=TBD
        机器人:重力=CENTER_HORIZONTAL | center_vertical
    />    < ImageView的
       机器人:ID =@ + ID / DIVIDER2
       机器人:layout_width =1dip
       机器人:layout_height =match_parent
       机器人:背景=@绘制/ appwidget_divider
       机器人:layout_alignRight =@ + ID / current_kw
       />    <的TextView
          机器人:ID =@ + ID / TEMP
          机器人:layout_toRightOf =@ + ID / DIVIDER2
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:重力=CENTER_HORIZONTAL
          机器人:TEXTSIZE =10SP
          机器人:文字颜色=#FFFFFF
          机器人:paddingLeft =1DP
          机器人:fadingEdgeLength =2DIP
          机器人:文字=温度
         />        <的TextView
            机器人:ID =@ + ID / estimate_cost
            机器人:layout_toRightOf =@ + ID / current_kw
            机器人:layout_below =@ + ID / TEMP
            机器人:paddingLeft =1DP
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=您的费用估计:
            机器人:TEXTSIZE =10SP
            机器人:重力=CENTER_HORIZONTAL
            机器人:layout_weight =1.0
           />        <的TextView
         机器人:ID =@ + ID / communitysize
         机器人:layout_toRightOf =@ + ID / current_kw
         机器人:layout_below =@ + ID / estimate_cost
         机器人:文字=社区的大小:
         机器人:TEXTSIZE =10SP
         机器人:paddingTop =1DP
         机器人:layout_width =WRAP_CONTENT
         机器人:重力=CENTER_HORIZONTAL
         机器人:layout_height =WRAP_CONTENT/>< / RelativeLayout的>


解决方案

试一试的教程

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@绘制/图标
    机器人:方向=横向>    <的ImageButton
    机器人:ID =@ + ID / message_button
    机器人:layout_centerVertical =真
    机器人:layout_width =0dip
    机器人:layout_height =75dip
    机器人:layout_weight =1.0
    机器人:SRC =@绘制/图标
    机器人:scaleType =中心
    />
<的LinearLayout
    机器人:ID =@ + ID / linearLayout2
    机器人:layout_width =0dip
    机器人:layout_weight =2
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:layout_gravity =center_vertical
    机器人:paddingLeft =18dip
    机器人:paddingRight =8DIP
   >
   < ImageView的
       机器人:layout_width =1dip
       机器人:layout_height =WRAP_CONTENT
       机器人:背景=@绘制/图标
       />    <的TextView
          机器人:ID =@ + ID / TEMP
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:TEXTSIZE =12SP
          机器人:文字颜色=#000000
          机器人:单线=真
          机器人:fadingEdge =横向
          机器人:fadingEdgeLength =2DIP
          机器人:文字=TBD
          机器人:ellipsize =无
         />
         <的TextView
            机器人:ID =@ + ID / communitystatus
            机器人:TEXTSIZE =12SP
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentRight =真
            机器人:行=1
            机器人:ellipsize =金字招牌
            机器人:fadingEdge =横向
            机器人:marqueeRepeatLimit =marquee_forever
            机器人:scrollHorizo​​ntally =真            机器人:可聚焦=真
            机器人:focusableInTouchMode =真
            机器人:文字颜色=#000000
            机器人:文字=简单的应用程序,展示了如何使用帐篷,用长文
         />
        <的TextView
         机器人:ID =@ + ID / communitysize
         机器人:文字=社区的大小:
         机器人:TEXTSIZE =12SP
         机器人:layout_below =@ + ID / CommunityStatusHeader
         机器人:paddingTop =5DP
         机器人:layout_width =WRAP_CONTENT
         机器人:重力=CENTER_HORIZONTAL
         机器人:layout_height =WRAP_CONTENT机器人:文字颜色=#000000/>
        <的TextView
            机器人:ID =@ + ID / estimate_cost
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=您的费用估计:
            机器人:TEXTSIZE =12SP
            机器人:layout_weight =1.0
            机器人:字体=SANS
            机器人:重力=CENTER_HORIZONTAL
            机器人:文字颜色=#000000/>
< / LinearLayout中>
< / LinearLayout中>

I have struggled with creating Android layouts and I'm still looking for a really solid tutorial that provides useful examples.

Currently, I am trying to create a Widget to be similar to many of the existing Android widgets on the market. For example, the simple weather widget that contains the temperature on the right side of the widget (next to an image) and general text on the right of the widget that includes more information such as the forecast. I have the following code and my image fails to load correctly. The text fails to load on the widget also. Can someone help to guide me so that I can at least see the image and some of the text:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:background="@drawable/appwidget_bg" 
    android:layout_height="fill_parent">

    <ImageButton 
    android:id="@+id/message_button"
    android:layout_width="100px"
    android:layout_height="wrap_content"
    android:src="@drawable/messages"
    android:scaleType="fitXY"
    />

   <ImageView
       android:id="@+id/divider"
       android:layout_width="1dip"
       android:layout_height="match_parent"
       android:background="@drawable/appwidget_divider"
       android:layout_alignRight="@+id/message_button"
       />    
   <TextView 
        android:id="@+id/current_kw"
        android:layout_toRightOf="@+id/divider"
        android:layout_width="80px"
        android:layout_height="wrap_content"
        android:textSize="18dp"
        android:textColor="#ffffff"
        android:typeface="sans"
        android:text="TBD"
        android:gravity="center_horizontal|center_vertical"
    />  

    <ImageView
       android:id="@+id/divider2"
       android:layout_width="1dip"
       android:layout_height="match_parent"
       android:background="@drawable/appwidget_divider"
       android:layout_alignRight="@+id/current_kw"
       />       

    <TextView 
          android:id="@+id/temp"
          android:layout_toRightOf="@+id/divider2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal"
          android:textSize="10sp"
          android:textColor="#ffffff"
          android:paddingLeft="1dp"
          android:fadingEdgeLength="2dip"
          android:text="Temperature"
         />    

        <TextView 
            android:id="@+id/estimate_cost"
            android:layout_toRightOf="@+id/current_kw"
            android:layout_below="@+id/temp"
            android:paddingLeft="1dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your estimated cost:"
            android:textSize="10sp"
            android:gravity="center_horizontal"
            android:layout_weight="1.0"
           />

        <TextView
         android:id="@+id/communitysize"
         android:layout_toRightOf="@+id/current_kw"
         android:layout_below="@+id/estimate_cost"
         android:text="Size of the community: "
         android:textSize="10sp"
         android:paddingTop="1dp"
         android:layout_width="wrap_content"
         android:gravity="center_horizontal"
         android:layout_height="wrap_content" /> 

</RelativeLayout>

解决方案

Try This tutorial

     <?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="fill_parent"
    android:background="@drawable/icon"
    android:orientation="horizontal" >

    <ImageButton 
    android:id="@+id/message_button"
    android:layout_centerVertical="true"
    android:layout_width="0dip"
    android:layout_height="75dip"
    android:layout_weight="1.0"
    android:src="@drawable/icon"
    android:scaleType="center"
    />
<LinearLayout
    android:id="@+id/linearLayout2" 
    android:layout_width="0dip"
    android:layout_weight="2"
    android:layout_height="fill_parent" 
    android:orientation="vertical"
    android:layout_gravity="center_vertical"
    android:paddingLeft="18dip"
    android:paddingRight="8dip"
   >
   <ImageView
       android:layout_width="1dip"
       android:layout_height="wrap_content"
       android:background="@drawable/icon"
       />    

    <TextView 
          android:id="@+id/temp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="12sp"
          android:textColor="#000000"
          android:singleLine="true"
          android:fadingEdge="horizontal"
          android:fadingEdgeLength="2dip"
          android:text="TBD"
          android:ellipsize="none"
         />    
         <TextView 
            android:id="@+id/communitystatus"
            android:textSize="12sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:lines="1"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"

            android:focusable="true"
            android:focusableInTouchMode="true"
            android:textColor="#000000"
            android:text="Simple application that shows how to use marquee, with a long text"
         />
        <TextView
         android:id="@+id/communitysize"
         android:text="Size of the community: "
         android:textSize="12sp"
         android:layout_below="@+id/CommunityStatusHeader"
         android:paddingTop="5dp"
         android:layout_width="wrap_content"
         android:gravity="center_horizontal"
         android:layout_height="wrap_content" android:textColor="#000000"/> 
        <TextView 
            android:id="@+id/estimate_cost"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your estimated cost:"
            android:textSize="12sp"
            android:layout_weight="1.0"
            android:typeface="sans" 
            android:gravity="center_horizontal" 
            android:textColor="#000000"/>
</LinearLayout>
</LinearLayout>

这篇关于Android小工具布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆