2017-11-28 10 views
1

私はここでは完全に厚くないと思いますが、TextViewのベースラインをConstraintLayoutのガイドラインに揃えることができません。ガイドラインにはベースラインがないようですが、これはかなり迷惑です。誰も私がこれを達成する方法を知っていますか?ここでは動作しないレイアウトXMLのビットが(これはConstraintLayout内にある)です。制約レイアウトでTextViewのベースラインをガイドラインに揃える

    <TextView 
        android:id="@+id/textToAlignBaseline" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="20dp" 
        android:maxLines="1" 
        android:paddingRight="6dp" 
        android:textAppearance="@style/TextStyles.Body" 
        app:layout_constraintBaseline_toBaselineOf="@+id/guidelineBottomMargin" 
        app:layout_constraintLeft_toLeftOf="parent" /> 

       <Button 
        android:id="@+id/buttonToAlignBottom" 
        android:layout_width="wrap_content" 
        android:layout_height="39dp" 
        android:layout_marginRight="20dp" 
        android:background="@drawable/selector_button_bg" 
        android:paddingLeft="16dp" 
        android:paddingRight="16dp" 
        android:text="@string/clickme" 
        android:textAppearance="@style/TextStyles.Body" 
        app:layout_constraintBottom_toTopOf="@+id/guidelineBottomMargin" 
        app:layout_constraintRight_toRightOf="parent" /> 

       <android.support.constraint.Guideline 
        android:id="@+id/guidelineBottomMargin" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        app:layout_constraintGuide_end="20dp" /> 
+0

レイアウトはどのように表示されるのですか?何をアーカイブしたいですか? –

答えて

1

私は解決策が出ているかもしれないと思う、私はベースラインを拡張し、「getBaseline」から0を返す試みたが、その私は代わりにAppCompatButtonを拡張し、代わりに 'getBaseline'から 'getMeasuredHeight'を返そうとしました(ImageViewは 'baselineAlignBottom'が使用されたときと同じように)、これは今正しく動作するようです。 TextViewは、ベースラインをガイドラインの代わりにボタンに合わせるために変更する必要があります。私はImageViewに似た属性でそれを整理する必要がありますが、これは私が今持っているものです:

public class ButtonBottomBaseline extends android.support.v7.widget.AppCompatButton { 
    public ButtonBottomBaseline(Context context) { 
     super(context); 
    } 

    public ButtonBottomBaseline(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public ButtonBottomBaseline(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @Override 
    public int getBaseline() { 
     return getMeasuredHeight(); 
    } 
} 
関連する問題