0

정렬, 그것이 무엇과 같아야하는 것은 아래 이미지에 표시됩니다 this is the Expected result, 수직으로 나는 각 <code>Seekbar</code> 단계에 텍스트 레이블이있을 것이다 위에 <code>Seekbar</code>를 만들 싶습니다 seekbars 엄지

이이의

<RelativeLayout 
       android:id="@+id/layout_font_size" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:id="@+id/txtFont_size_hint" 
        style="@style/textStyle" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/Aa" /> 

       <LinearLayout 
        android:id="@+id/layout_seekbar_interval_holder" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/txtFont_size_hint" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="@dimen/margin_16dp" 
        android:orientation="horizontal" 
        android:weightSum="5"> 

        <TextView 
         android:id="@+id/txtSize_14" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:focusable="false" 
         android:gravity="center" 
         android:text="@string/setting_font_text" 
         android:textSize="@dimen/font_size_14" /> 

        <TextView 
         android:id="@+id/txtSize_18" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:focusable="false" 
         android:gravity="center" 
         android:text="@string/setting_font_text" 
         android:textSize="@dimen/font_size_18sp" /> 

        <TextView 
         android:id="@+id/txtSize_24" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:focusable="false" 
         android:gravity="center" 
         android:text="@string/setting_font_text" 
         android:textSize="@dimen/font_size_24sp" /> 

        <TextView 
         android:id="@+id/textSize_30" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:focusable="false" 
         android:gravity="center" 
         android:text="@string/setting_font_text" 
         android:textSize="@dimen/font_size_30sp" /> 

        <TextView 
         android:id="@+id/txtSize_36" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:focusable="false" 
         android:gravity="center" 
         android:text="@string/setting_font_text" 
         android:textSize="@dimen/font_size_36sp" /> 
       </LinearLayout> 

       <SeekBar 
        android:id="@+id/seekBarSetting_font_size" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"      android:layout_below="@id/layout_seekbar_interval_holder" 
        android:layout_marginLeft="@dimen/margin_16dp" 
        android:layout_marginRight="@dimen/margin_16dp" 
        android:max="4" 
        android:theme="@style/seekBarYelloStyle" /> 
      </RelativeLayout> 

출력

enter image description here

내가 무슨 짓을하는 예상 된 결과,이다

레이아웃이 예상 한 것과 비슷하게 보이지만 탐색 모음 엄지 손가락을 움직이는 동안 엄지 손가락이 TextView과 수직으로 정렬되지 않으므로 여기의 문제는 탐색 막대 엄지 손가락이 seekBar 단계를 나타내는 텍스트와 수직으로 정렬되어 있지 않기 때문입니다.

또한 seekbars 너비를 단계별로 나누어서 TextView의 정확한 위치를 계산해 보았습니다. 여기에 5 단계가 있지만 첫 번째 위치는 0 번째 위치에 있으므로 전체 seekbar 너비를 4로 나누고 그에 따라 각 텍스트를 배치했습니다. 그러나 예상되는 해결책을 얻지 못했습니다.

나는 조금 혼란스러워하며 가능한 한 빨리 간단한 해결책을 원합니다.

PS는 동적으로 생성 된 뷰의 출력의 스크린 샷이위한 참조

enter image description here

+0

당신이 시도 방법 공유 코드가 그들을 정렬 할 수 – shadygoneinsane

+0

의이 레이아웃에 ... 당신은?, 구성 요소 정의에 대해 얘기 –

+0

해결책을 찾은 경우 답변을 게시하십시오 :) – shadygoneinsane

답변

1

레이아웃 부착되어

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="android.sample.MainActivity"> 

<TextView 
    android:id="@+id/txtFont_size_hint" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Sizes"/> 
<LinearLayout 
    android:id="@+id/ll" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:weightSum="5"> 

     <LinearLayout 
    android:id="@+id/ll" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="5"> 

    <TextView 
     android:id="@+id/txtSize1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/setting_font_text" 
     android:textSize="15sp"/> 

    <TextView 
     android:id="@+id/txtSize_18" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/setting_font_text" 
     android:textSize="20sp"/> 

    <TextView 
     android:id="@+id/txtSize_24" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:focusable="false" 
     android:gravity="center" 
     android:text="@string/setting_font_text" 
     android:textSize="25sp"/> 

    <TextView 
     android:id="@+id/textSize_30" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:focusable="false" 
     android:gravity="center" 
     android:text="@string/setting_font_text" 
     android:textSize="30sp"/> 

    <TextView 
     android:id="@+id/txtSize_36" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:focusable="false" 
     android:gravity="center" 
     android:text="@string/setting_font_text" 
     android:textSize="35sp"/> 
</LinearLayout> 

<SeekBar 
    android:id="@+id/seekBarSetting_font_size" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:max="4"/> 

이제 짓이고 Seekbar의 너비가 마지막까지의 중심까지 정렬 TextView whi 이 경우 채널은 txtSize_36 을하고 android:max="4" 이렇게 다섯 개 가지 값 활동에 대한

코드는 (당신이 원하는만큼로 변경할 수 있습니다)이 있습니다로 EMS를 설정 한 다음은

public class MainActivity extends AppCompatActivity { 
SeekBar seekBar; 

private LinearLayout bar, ll; 
TextView txtSize_14, txtSize_36; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    seekBar = (SeekBar) findViewById(R.id.seekBarSetting_font_size); 

    txtSize_14 = (TextView) findViewById(R.id.txtSize1); 
    txtSize_36 = (TextView) findViewById(R.id.txtSize_36); 
    ll = (LinearLayout) findViewById(R.id.ll); 

} 
    float density; 
    @Override 
    protected void onResume() { 
    super.onResume(); 

    ViewTreeObserver vto = ll.getViewTreeObserver(); 
//****old code (may not work on all orientations)**** 
/*vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 
       ll.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
      } else { 
       ll.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
      } 
      int width = ll.getMeasuredWidth(); 
      int height = ll.getMeasuredHeight(); 

      ViewGroup.LayoutParams params = seekBar.getLayoutParams(); 

      density = getResources().getDisplayMetrics().density; 
      int newwidth = (int) (txtSize_14.getLeft()/density); 
      newwidth = newwidth+ (txtSize_36.getLeft() + txtSize_36.getRight())/2; 
      params.width = newwidth; 
      seekBar.setLayoutParams(params); 

     } 
    });*/ 

    //****new code (should work on all orientations)**** 
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 
       ll.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
      } else { 
       ll.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
      } 
      seekBar.setPadding(15, 0, 15, 0); 
      seekBar.setX(((txtSize_14.getLeft() + txtSize_14.getRight())/2) - 15); 

      ViewGroup.LayoutParams params = seekBar.getLayoutParams(); 

      int centerwidth = ((txtSize_36.getLeft() + txtSize_36.getRight())/2) - ((txtSize_14.getLeft() + txtSize_14.getRight())/2) + 15; 
      params.width = centerwidth; 
      seekBar.setLayoutParams(params); 
     } 
    }); 

} 

} 

있다가 스크린 샷 참조 (나는 seekbar의 모든 위치에 clubbed있다) : enter image description here

+0

고마워요, 많은 시간을 보냈습니다.그러나 마침내 그것은 작동합니다, 당신의 응답을 위해 +10 –

+1

이봐, 나는 코드를 다시 작성 했으므로 이전 코드를 더 버그가 있음을 발견했습니다. – shadygoneinsane

0

솔직히 말해서 XML을 사용하여 이것을 정렬하는 데는 시간이 걸렸다. 첫번째 레이블과 마지막 레이블은 다른 레이블과 다른 위치에 있습니다 .... 엄지의 크기를 15dp에서 변경하는 경우 첫 번째 및 마지막 TextView 여백과 공백 크기를 변경해야합니다 (margin + space = 엄지 손가락 크기)

preview

   <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:paddingRight="0dp" 
        android:paddingLeft="0dp"> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:paddingLeft="0dp"> 

         <TextView 
          android:text="7 days" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:textColor="@color/colorPrimaryBackground" 
          android:gravity="left|center" 
          android:textSize="@dimen/textSize_smallest" 
          android:layout_weight="0.5" 
          android:layout_marginLeft="5dp"/> 

         <Space 
          android:layout_width="10dp" 
          android:layout_height="match_parent"/> 

         <TextView 
          android:text="1 month" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:textColor="@color/colorPrimaryBackground" 
          android:gravity="center" 
          android:textSize="@dimen/textSize_smallest" 
          android:layout_weight="1" 
          android:layout_marginRight="0dp" 
          android:id="@+id/textView" /> 

         <TextView 
          android:text="3 months" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:textColor="@color/colorPrimaryBackground" 
          android:gravity="center" 
          android:textSize="@dimen/textSize_smallest" 
          android:layout_weight="1" 
          android:layout_marginRight="0dp"/> 

         <TextView 
          android:text="1 year" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:textColor="@color/colorPrimaryBackground" 
          android:gravity="center" 
          android:textSize="@dimen/textSize_smallest" 
          android:layout_weight="1" 
          android:layout_marginLeft="0dp"/> 

         <TextView 
          android:text="3 years" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:textColor="@color/colorPrimaryBackground" 
          android:gravity="center" 
          android:textSize="@dimen/textSize_smallest" 
          android:layout_weight="1" 
          android:layout_marginLeft="0dp"/> 

         <Space 
          android:layout_width="10dp" 
          android:layout_height="match_parent"/> 

         <TextView 
          android:text="5 years" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:textColor="@color/colorPrimaryBackground" 
          android:gravity="right|center" 
          android:textSize="@dimen/textSize_smallest" 
          android:layout_weight="0.5" 
          android:layout_marginRight="5dp"/> 

        </LinearLayout> 


       </RelativeLayout> 
관련 문제