gpt4 book ai didi

java - 如何在屏幕尺寸变化时动态管理TextViews的位置

转载 作者:行者123 更新时间:2023-11-29 06:27:58 25 4
gpt4 key购买 nike

我在一个水平布局中有两个 TextView ,第一个是普通文本,第二个是可点击的不同颜色。

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 英寸及以上)上看起来很棒, 但是当屏幕尺寸较小时,第二个 textview 变得很奇怪。!我希望它自动将自己定位在第一个 TextView 下方或使其父布局方向垂直..!!

这是它的样子。!

enter image description here


更新 #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);
}

最佳答案

同样的问题here或者来自the original document

关于java - 如何在屏幕尺寸变化时动态管理TextViews的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47483573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com