2012-01-18 57 views
2

我有一個textview和imageview在同一行的佈局。Android的textview測試是在其他用戶界面

如果文本太長,它會覆蓋imageview。 我使用layout作爲wrap_content。

任何想法如何解決它?

我想這樣做,而沒有指定以像素爲單位的寬度。

問題與@ + ID/ShowRecipe_RecipeNameId和@ + ID/ShowRecipe_PTimeImageViewId 這裏是XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/main_bg" > 


    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/ShowRecipe_RecipeNameId" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="5dp" 
      android:textColor="@color/header_orange" 
      android:text="RecipeName" 
      android:textSize="21dip" /> 

     <TextView 
      android:id="@+id/ShowRecipe_AuthorId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/ShowRecipe_RecipeNameId" 
      android:layout_below="@+id/ShowRecipe_RecipeNameId" 
      android:layout_alignTop="@+id/ShowRecipe_DifficultyImageViewId" 
      android:textColor="@color/author_blue" 
      android:text="Author" 
      android:textSize="21dip" /> 

     <ImageView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:src="@drawable/add_to_favourite" 
      android:layout_alignParentRight="true" 
      android:layout_marginTop="5dp" 
      android:layout_marginRight="5dp" 
      android:id="@+id/addRemoveFromFavouritesImageViewId" /> 

<!-- <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/refresh_button" 
      android:id="@+id/ShowRecipe_RefreshImageViewId" 
      android:layout_alignTop="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_toLeftOf="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_marginRight="5dp" /> --> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/rate_recipe_button" 
      android:id="@+id/ShowRecipe_RateImageViewId" 
      android:layout_toLeftOf="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_alignTop="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_marginRight="5dp" /> 

     <ImageView 
      android:src="@drawable/time_icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/ShowRecipe_RateImageViewId" 
      android:layout_alignRight="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_marginTop="10dp" 
      android:id="@+id/ShowRecipe_PTimeImageViewId" /> 

     <ImageView 
      android:src="@drawable/difficulty_hard_icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_alignLeft="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_marginTop="5dp" 
      android:id="@+id/ShowRecipe_DifficultyImageViewId" /> 

    </RelativeLayout> 


    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/ShowRecipe_RatingBarId" > 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="5dp"> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:padding="5dp" 
       android:layout_height="match_parent" 
       android:layout_width="match_parent" 
       android:layout_weight="1" /> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/recipe_book_tabs_bg" 
       android:layout_gravity="bottom" /> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 

回答

1

我認爲通過在TextView上放置android:layout_toLeftOf="@+id/ShowRecipe_PTimeImageViewId"並使TextView寬度爲fill_parent可以解決問題。我修改了xml。請檢查:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/main_bg"> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/ShowRecipe_RecipeNameId" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_marginLeft="5dp" 
      android:text="RecipeName" 
      android:layout_toLeftOf="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_alignLeft="@+id/ShowRecipe_PTimeImageViewId" 
      android:textSize="21dip" /> 

     <TextView 
      android:id="@+id/ShowRecipe_AuthorId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/ShowRecipe_RecipeNameId" 
      android:layout_alignTop="@+id/ShowRecipe_DifficultyImageViewId" 
      android:layout_below="@+id/ShowRecipe_RecipeNameId" 
      android:text="Author" 
      android:textSize="21dip" /> 

     <ImageView 
      android:id="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="5dp" 
      android:src="@drawable/icon" /> 

     <!-- 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/refresh_button" 
      android:id="@+id/ShowRecipe_RefreshImageViewId" 
      android:layout_alignTop="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_toLeftOf="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_marginRight="5dp" /> 
     --> 

     <ImageView 
      android:id="@+id/ShowRecipe_RateImageViewId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_marginRight="5dp" 
      android:layout_toLeftOf="@+id/addRemoveFromFavouritesImageViewId" 
      android:src="@drawable/icon" /> 

     <ImageView 
      android:id="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/addRemoveFromFavouritesImageViewId" 
      android:layout_below="@+id/ShowRecipe_RateImageViewId" 
      android:layout_marginTop="10dp" 
      android:src="@drawable/icon" /> 

     <ImageView 
      android:id="@+id/ShowRecipe_DifficultyImageViewId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_below="@+id/ShowRecipe_PTimeImageViewId" 
      android:layout_marginTop="5dp" 
      android:src="@drawable/icon" /> 
    </RelativeLayout> 
    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/ShowRecipe_RatingBarId" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:padding="5dp" > 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="5dp" /> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       /> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 
1

你可以使它成爲一個相對佈局或垂直佈局。

或者,使用dp而不是px,因爲dp會相對於其屏幕縮放。

+0

請參閱我的編輯 – user1136875 2012-01-18 18:26:49

1

在您的imageview和textview中使用佈局權重標記。

或使用相對佈局。在那裏你可以說它應該在哪裏找到。