하나의 가로 레이아웃에 두 개의 텍스트 뷰가 있습니다. 첫 번째 텍스트는 일반 텍스트이고 두 번째 텍스트는 다른 색상으로 클릭 할 수 있습니다.화면 크기가 변경 될 때 TextViews의 위치를 동적으로 관리하는 방법
XML
<!--inside rootlayout..-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:maxLines="2"
android:text="By clicking sign up, you agree to our "
android:textColor="@color/black"
android:textSize="12sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="terms and conditions"
android:textColor="@color/colorPrimary"
android:textSize="12sp"
android:clickable="true"/>
</LinearLayout>
그리고 그것은 나에게 큰 대형 스크린에 모습 (위의 4.7 인치), 하지만 화면 크기가 낮은 경우, 두 번째 텍스트 뷰 이상한 얻을 수 있습니다.! 자동으로 첫 번째 텍스트 뷰 아래에 배치하거나 부모 레이아웃 방향을 세로로 만듭니다. !!
여기 보이는 모양입니다.!
업데이트 # 1
ForegroundColorSpan
이 변경되지 않습니다 왜!? 내가 설정 한 색상 자원에 관계없이 항상 파란색 또는 검은 색으로 표시됩니다.
private void handleTermsConditions() {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(termsTxt.getText());
stringBuilder.setSpan(new StyleSpan(Typeface.BOLD), 38, 58, 0);
int color = ContextCompat.getColor(RegistrationActivity.this, R.color.colorPrimary);
ForegroundColorSpan fcs = new ForegroundColorSpan(color);
stringBuilder.setSpan(fcs, termsTxt.getText().length() - 20, termsTxt.getText().length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
Toast.makeText(RegistrationActivity.this, "Click", Toast.LENGTH_SHORT)
.show();
}
};
stringBuilder.setSpan(clickableSpan, 38, 58, Spanned.SPAN_POINT_MARK);
termsTxt.setMovementMethod(LinkMovementMethod.getInstance());
termsTxt.setText(stringBuilder);
}
필자는 자동으로 발생한다고 생각합니다. 충분한 공간이 있으면 공간에 따라 다르므로 첫 번째 화면과 같을 것입니다. –