2016-09-13 2 views
1

나는 이상한 문제가 있습니다. 이미지 아래에캔트가 도구 막대에서 텍스트 뷰를 위로 이동합니다.

임 바쁜 작업은 :

Cart counter

문제는 내가 위쪽으로 이동하려면 텍스트 뷰 ("9"이미지에서)을 얻을 필요가있다. 이 이미지 + 텍스트보기는 툴바에 있습니다.

레이아웃 파일에서 이미지를 위아래로 움직일 수 있지만 툴바의 공간 부족으로 인해 잘릴 수 있습니다. 따라서 이미지를 아래쪽으로 이동하면 카트 아이콘이 아래쪽으로 잘 리게됩니다.

위로 이동하려면 카운터가 필요합니다. 나는 텍스트 뷰에 아래 시도 :

안드로이드 : paddingBottom = "9dp"

안드로이드 : layout_marginBottom = "9dp"

하지만 둘의 텍스트 뷰를 이동합니다.

아래 레이아웃 파일 참조하십시오

<RelativeLayout android:id="@+id/counterPanel" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
    android:id="@+id/cartCountIcon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/cart_dark"/> 

    <TextView 
    android:id="@+id/cartCount" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerInParent="true" 
    android:textColor="@color/orange_6" 
    tools:text="7"/> 

</RelativeLayout> 

을 내가 코드에서이 레이아웃을 사용하고 방법이 있습니다 :

public static Drawable buildCartDrawable(Context context, int count, boolean isCartLight) { 
    LayoutInflater inflater = LayoutInflater.from(context); 

    View view = inflater.inflate(R.layout.item_cart_counter_menu_item, null); 
    TextView textView = (TextView) view.findViewById(R.id.cartCount); 
    ImageView cartIcon = (ImageView) view.findViewById(R.id.cartCountIcon); 
    int backgroundImageId; 

    if (isCartLight) { 
     textView.setTextColor(ContextCompat.getColor(context, R.color.white)); 
     backgroundImageId = R.drawable.cart_empty; 
     if (count > 0) { 
     backgroundImageId = R.drawable.cart; 
     } 
    } else { 
     backgroundImageId = R.drawable.cart_empty_dark; 
     if (count > 0) { 
     backgroundImageId = R.drawable.cart_dark; 
     } 
    } 
    cartIcon.setBackgroundResource(backgroundImageId); 

    if (count == 0) { 
     textView.setVisibility(View.GONE); 
    } else if (count < 10) { 
     textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); 
    } else { 
     textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11); 
    } 

    textView.setText(String.valueOf(count)); 
    view.measure(
      View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), 
      View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 
    view.layout(0, 0, cartIcon.getMeasuredWidth(), cartIcon.getMeasuredHeight()); 
    view.setDrawingCacheEnabled(true); 
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); 
    view.setDrawingCacheEnabled(false); 

    return new BitmapDrawable(BobeApplication.getAppContext().getResources(), bitmap); 
    } 

나는 대부분의 약 3/4dp을 이동하려면 텍스트 뷰가 필요합니다 하지만 그것은 도구 모음에 중심에 머물 것으로 보인다. 그리고 나는 이것에 대한 해결책을 볼 수 없다.

+0

시도 추가 marginBottom 시도 – xanexpt

답변

0

RelativeLayout 대신 FrameLayout을 사용하십시오. 어쩌면 항목이 올라갈 공간이 doenst뿐만 아니라 위쪽 여백과 layout_alignParentTop = "true"로 플레이 : 텍스트 뷰에 "센터"= layout_gravity를 추가하고 어쩌면 안드로이드를 제거하는

<FrameLayout android:id="@+id/counterPanel" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
    android:id="@+id/cartCountIcon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/cart_dark"/> 

    <TextView 
    android:id="@+id/cartCount" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginBottom="2dp" 
    android:textColor="@color/orange_6" 
    tools:text="7"/> 

</FrameLayout> 
관련 문제