2012-10-22 55 views
0

我需要帮助才能让我的图像和文本的布局工作。Android,布局图像和文本

我希望图像缩放到与我的TextView使用的高度相同。 我还希望图像留给文本。 例如#在我的图像

# "My Text" 

## "My long text 
## is this here" 

图像的witdh将会使图像保持方面。

我的代码是现在这个,基本的布局工作,但形象是大。

 <LinearLayout 
      android:id="@+id/packet_list_view_layout_subvehicle" android:layout_width="fill_parent" 
      android:layout_weight="1" android:orientation="horizontal" 
      android:gravity="left" android:layout_height="wrap_content"> 
      <ImageView 
       android:id="@+id/packet_list_view_layout_subvehicle_image" 
       android:src="@drawable/packet" 
       android:scaleType="fitCenter" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
      <TextView 
       android:id="@+id/packet_list_view_layout_subvehicle_text" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="===================" 
       /> 

编辑1

A以外的尝试给我相同的结果。

 <LinearLayout 
      android:id="@+id/packet_list_view_layout_subvehicle" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:orientation="horizontal" 
      android:gravity="left" 
      android:layout_height="wrap_content" 
     > 
      <ImageView 
       android:id="@+id/packet_list_view_layout_subvehicle_image" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:scaleType="fitCenter" 
       android:src="@drawable/packet" /> 
      <TextView 
       android:id="@+id/packet_list_view_layout_subvehicle_text" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:text="TV's (20) to London" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 
     </LinearLayout> 

EDIT 2

我现在已经找到了一半的工作代码,这里的问题是图像的宽度为原点的宽度,而不是新的规模witdh。

 <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:id="@+id/packet_list_view_layout_subvehicle" 
     > 
      <ImageView 
       android:id="@+id/packet_list_view_layout_subvehicle_imageAA" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:src="@drawable/packet" 
       /> 

      <TextView 
       android:id="@+id/packet_list_view_layout_subvehicle_text" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="center|left" 
       android:text="TV's (20) to London" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 
     </LinearLayout> 

回答

0

我终于找到了一种工作方式,不是很好,但为我工作。

我的代码现在

 <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:id="@+id/packet_list_view_layout_subvehicle" 
     > 
      <mypacket.MyImageView 
       android:id="@+id/packet_list_view_layout_subvehicle_imageAA" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:src="@drawable/packet" 
       /> 

      <TextView 
       android:id="@+id/packet_list_view_layout_subvehicle_text" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="center|left" 
       android:text="TV's (20) to London" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 
     </LinearLayout> 

而且mypacket.MyImageView是此代码。

public class MyImageView extends ImageView { 

    public MyImageView(Context context) { 
     super(context); 
    } 
    public MyImageView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
    public MyImageView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 

    } 
    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(heightMeasureSpec, heightMeasureSpec); 
    } 
} 

编辑:在真正的,我不使用此,基地之一的一些错误与系统如何calc下的大小,即做形象会更大然后需要,而这也将这样做文字翘曲成两条线。在最后我使用一个正常的ImageView并设置修正hegth和withd。