2011-11-27 3 views
0

저는 Android 레이아웃을 만드는 데 어려움을 겪었습니다. 유용한 예제를 제공하는 정말 유용한 튜토리얼을 찾고 있습니다.Android 위젯 레이아웃

현재 시장에 나와있는 많은 기존 Android 위젯과 비슷하게 위젯을 만들려고합니다. 예를 들어 위젯 오른쪽 (이미지 옆)에 온도가 포함 된 간단한 날씨 위젯과 예측과 같은 추가 정보가 포함 된 위젯 오른쪽에있는 일반 텍스트가 들어 있습니다. 다음 코드를 가지고 이미지가 올바르게로드되지 않습니다. 텍스트가 위젯에도로드되지 않습니다.

<?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> 

답변

1

써니 튜토리얼에 대한 링크를위한이 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> 
+0

감사를보십시오 : 나는 적어도 이미지와 텍스트의 일부를 볼 수 있도록 누군가가 나를 인도하는 데 도움이 될 수 있습니다. 이것은 도움이됩니다. 내 코드를 현재 작동하는 코드로 업데이트했습니다. 궁금 해서요, 왜 내 이미지 주위에 경계선이있는 것처럼 보입니까? –

+0

ImageButton 대신 ImageView를 사용해야합니다. 그게 내 문제를 해결해 줬어. 감사! –