【问题标题】:Android change height width of view according to requirements at runtimeAndroid在运行时根据要求改变视图的高度宽度
【发布时间】:2014-10-31 03:05:38
【问题描述】:

我在运行时有一个 textview,我将它旋转 120 度,使用 mytextview.setRotation(120);

要做的问题是它剪切了我的文本(无法在视图外看到文本)

我的布局是

<RelativeLayout 
    android:layout_width="wrap_content"
    android:id="@+id/rel"
    android:background="@android:color/darker_gray"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
   android:padding="20dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:longClickable="true"
        android:text="TextView"
        android:typeface="monospace" />
</RelativeLayout>

我该怎么办?旋转角度是动态的并且根据用户而变化。如何克服这个问题?

实际上我可以旋转视图,但我的 textview 不能显示整个字符串。即如果字符串是Hello,那么在旋转后它只显示Hel,之后不显示单词。

【问题讨论】:

    标签: android layout textview


    【解决方案1】:

    这两个选项之一可以帮助您:

     android:adjustviewbounds="true"
    

    在运行时以编程方式:旋转后,您可以设置宽度和高度:

     view. getlayoutparams().widht = ...
     view. getlayoutparams().height = ...
    

    【讨论】:

    • 使用视图。 getlayoutparams().widht = ... 查看。 getlayoutparams().height = .. 它会固定大小,但我需要它根据动态不同的屏幕和不同的字符串长度
    • 然后编写一个方法,在其中根据源参数(屏幕、字符串)动态设置布局参数。在我看来,没有官方的 android 解决方案。你可以看看这个项目github.com/rongi/rotate-layout
    猜你喜欢
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 2015-03-14
    • 2011-03-28
    • 2021-03-31
    • 1970-01-01
    相关资源
    最近更新 更多