2012-01-18 2 views
2

동일한 줄에 textview와 imageview가있는 레이아웃이 있습니다.다른 UI에 Android 텍스트 뷰 테스트가 있습니다.

텍스트가 너무 길면 이미지 뷰를 넘어갑니다. 레이아웃을 wrap_content로 사용합니다.

어떻게 고칠 수 있습니까?

픽셀 단위로 너비를 지정하지 않고이 작업을 수행하고 싶습니다.

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

당신은 그것을 상대 레이아웃이나 수직 레이아웃 그것을 만들 수 :

문제는 @ + ID/ShowRecipe_RecipeNameId와 @ + ID 여기에/ShowRecipe_PTimeImageViewId 와 것은 XML이다.

또는 px 대신 dp를 사용하십시오. dp가 화면에 상대적으로 크기를 조정하기 때문입니다.

+0

내 편집을 참조하십시오. – user1136875

1

이미지 뷰와 텍스트 뷰에 레이아웃 가중 태그를 사용하십시오.

또는 상대 레이아웃을 사용하십시오. 어디에서 찾아야하는지 말할 수 있습니다.

관련 문제