2016-07-12 2 views
0
  • Title의 Textview와 아이콘의 Imageview가 포함 된 선형 레이아웃을 사용하는 작업 표시 줄의 레이아웃을 만들었습니다.
  • 제목에 긴 텍스트가 설정되어 있으면 텍스트와 부분 아이콘도 숨겨집니다.
  • 이미지에서 볼 수 있습니다.
  • 아이콘이 필요합니다. 텍스트 바로 오른쪽에서 텍스트 가중치 = 1을 사용하지 않습니다.

XML이 문제를 해결

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/actionbar_color" 
android:gravity="center" 
android:orientation="horizontal"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_weight="1" 
    android:layout_height="?android:attr/actionBarSize" 
    android:orientation="horizontal"> 
    <ImageView 
     android:id="@+id/imgActionLeftIcon" 
     android:layout_width="?android:attr/actionBarSize" 
     android:layout_height="match_parent" 
     android:layout_margin="@dimen/action_btn_margine" 
     android:src="@drawable/menu_logo" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="horizontal"> 
     <TextView 
      android:id="@+id/txtActionTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:gravity="center" 
      android:maxLines="1" 
      android:ellipsize="end" 
      android:text="Medium Text ghjhjgjkghdfggh" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#FFFFFF" 
      android:textStyle="bold" /> 
     <ImageView 
      android:layout_width="@dimen/action_btn_height_width" 
      android:layout_height="match_parent" 
      android:padding="@dimen/_2sdp" 
      android:src="@mipmap/ic_launcher" /> 
    </LinearLayout> 
    <ImageView 
     android:id="@+id/imgActionRightIcon" 
     android:layout_width="?android:attr/actionBarSize" 
     android:layout_height="match_parent" 
     android:layout_margin="@dimen/action_btn_margine" 
     android:src="@drawable/menu_logo" /> 
</LinearLayout> 

Textview는 긴 텍스트와보기를 숨 깁니다.

출력

enter image description here

답변

1

. 내 코드 (추가 속성 layout_weight)를 참조하십시오 :

<TextView 
      android:id="@+id/txtActionTitle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center_vertical" 
      android:gravity="center" 
      android:maxLines="1" 
      android:ellipsize="end" 
      android:text="Medium Text ghjhjgjkghdfggh" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#FFFFFF" 
      android:textStyle="bold" /> 
+0

답변에 대한 감사하지만 난 또한 위의 정의를 내가 이미 사용 안드로이드 :에 layout_weight = "1"은 작동하지만 문제는 텍스트 뷰 텍스트가 작은 경우 다음도에 넣어 아이콘이다 마지막으로 제목과 아이콘 사이의 여백을 찾습니다. 그래서 android : layout_weight = "1"을 사용하지 않았습니다. – Sam

+0

@Sam. 달성해야 할 것을 사진으로 게시 할 수 있습니까? –

관련 문제