我试图在一个文本块旁边显示一条蓝线,非常像这样:

这是我的代码:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/blue_line" />
Run Code Online (Sandbox Code Playgroud)
blue_line是一个jpg文件.一个蓝色的矩形.无论textview中的文本如何,它都以原始大小显示.如何根据文字的高度动态调整其高度?比如当文字少量文字时缩短,文字更多时更长......
我有一个RadioGroup我试图缩小,因为它太大了.所以我使用setScaleX()并setScaleY()缩小它.
它可以工作,但问题是当我缩放时,视图会改变X和Y的位置.我希望它在缩放后保持相同的左上角坐标.如何在缩放后使View保持不变?
见下面的代码:
CSRadioButton radiobutton = (CSRadioButton) field;
RadioGroup rg = new RadioGroup(this);
rg.setOrientation(RadioGroup.VERTICAL);
JSONArray choices = radiobutton.getChoices();
for(int j = 0; j < choices.length(); j++){
JSONObject currObj = choices.getJSONObject(j);
String text = currObj.getString("text");
RadioButton rb = new RadioButton(this);
rb.setText(text);
rg.addView(rb);
}
rscroll.addView(rg, lp);
rg.setScaleX(0.7f);
rg.setScaleY(0.7f);
Run Code Online (Sandbox Code Playgroud)