如何在textview字段中设置永久文本?

时间:2018-03-29 12:36:54

标签: android android-studio button textview

有一个名为" A"的按钮。没有任何重力。所以A在左侧。我想在此按钮的中心设置另一个文本而不更改字符串" A"它的位置?我怎么能这样做?

对不起,我希望你理解我的英文。

2 个答案:

答案 0 :(得分:1)

我认为您不能在一个按钮内执行此操作,但您可以创建一个看起来像extension Array { init?(data: Data) { // This check should be more complex, but here we just check if total byte count divides to one element size in bytes guard data.count % MemoryLayout<Element>.size == 0 else { return nil } let elementCount = data.count / MemoryLayout<Element>.size let buffer = UnsafeMutableBufferPointer<Element>.allocate(capacity: elementCount) data.copyBytes(to: buffer) self = buffer.map({$0}) buffer.deallocate() } // Wrapped here code above var data: Data { return self.withUnsafeBufferPointer { pointer in return Data(buffer: pointer) } } } let converted: [Double]? = Array(data: CMX.data) // converted now should be equal to CMX 的{​​{1}},然后为不同的字符设置不同的RelativeLayout

在这种情况下,您的代码应如下所示

Button

并且您还可以创建一个选择器并将其应用于RelativeLayout以实现按钮的效果。遵循此https://stackoverflow.com/a/14024007/3789993

希望有所帮助

答案 1 :(得分:0)

最简单的方法,但不建议只是在&#34; A&#34;之后添加空格:

select x1.*, x2.KTNR, x3.J6NQ
from 
    (select D0HONB as HONB, D0HHNB as HHNB, 
        (
            select DHHHNB 
            from ECDHREP 
            where DHAOEQ = D0ATEQ and DHJRCD = D0KNCD 
            order by DHEJDT desc 
            FETCH FIRST 1 ROW ONLY
        ) as STC_HHNB,
        (
            select FIQ9NB 
            from DCFIREP 
            where FIQ7NB = D0Q7NB 
              AND FIBAEQ = D0ATEQ 
              and FISQCD = D0KNCD 
              and FIGZSZ in ('POS', 'ACT', 'MAN', 'HLD') 
            order by FIYCNB desc 
            FETCH FIRST 1 ROW ONLY
        ) as BL_Q9NB,
        (
            select AAKPNR 
            from C1AACPP 
            where AACEEQ = D0ATEQ and AARCCE = D0KNCD and AARDCE = D0KOCD 
            order by AAHMDT desc, AANENO desc 
            FETCH FIRST 1 ROW ONLY 
        ) as NULL_KPNR  
        from ECD0REP
    ) as x1 
left outer join (
        select AAKPNR as null_kpnr, max(ABKTNR) as KTNR 
        from C1AACPP 
          left outer join C1ABCPP on AAKPNR = ABKPNR 
        group by AAKPNR
    ) as X2 on x1.NULL_KPNR = x2.null_KPNR 
left outer join (
        select ACKPNR as KPNR, count(*) as J6NQ 
        from C1ACCPP 
        WHERE ACJNDD = 'Y' 
        group by ACKPNR
    ) as X3 on x1.NULL_KPNR = x3.KPNR 

最好的方法是建立一个看起来像按钮的布局:

<Button
  android:layout_width="WidthThatYouWant"
  android:layout_height="HeightThatYouWant"
  android:text="A            TextYouWantToAdd"
 />

然后,您可以自定义LinearLayout,使其具有与按钮相同的格式,添加:

<RelativeLayout
    android:layout_width="WidthThatYouWant"
    android:layout_height="HeightThatYouWant"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextYouWantToAdd"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

例如,这里是一个红色和圆形的按钮。

文件circularRedButton.xml是:

android:background="@drawable/circularRedButton.xml"