2016-07-25 46 views
-2

我想做出兩個水平佈局,底部是用於放置基本數字,頂部是用於顯示數字的電源的位置:1²1²1² I' m使用兩個editText。一個用於下標,另一個用於SuperScript。 ,還有一個按鈕和一個TextView,通過點擊按鈕顯示結果。 我的代碼: enter image description here 結果: :如何設置底座和電源編號的兩個佈局

enter image description here

你怎麼看這樣的想法?

+0

請詳細解釋您的意思。你真的需要兩個「水平佈局」嗎?或者你只是想能夠顯示上標指數? –

+0

沒有。我只想從用戶那裏獲得並保存一些數學和物理表達式,其中可能包含下標和上標nmubers和符號 – CLONER

+0

那麼,在[本文]中有一些超級和下標的基本示例(http://stackoverflow.com/questions/3543454/subscript-and-superscript-a-string-in-android),但是如果你想在用戶輸入時將它應用到用戶的輸入中,這將需要更多的工作。 –

回答

0

試試這個按照您的要求

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="20dp"> 

    <TextView 
     android:id="@+id/base_value" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="1" 
     android:textColor="@android:color/black" 
     android:textSize="20sp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:layout_toRightOf="@+id/base_value" 
     android:gravity="top" 
     android:text="n" 
     android:textColor="@android:color/black" 
     android:textSize="12sp" /> 

</RelativeLayout> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="30dp" 
    android:gravity="center" 
    android:layout_margin="20dp"> 

    <TextView 
     android:id="@+id/base_value_new" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:text="1" 
     android:textColor="@android:color/black" 
     android:textSize="20sp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     android:layout_toRightOf="@+id/base_value_new" 
     android:gravity="bottom" 
     android:text="n" 
     android:textColor="@android:color/black" 
     android:textSize="12sp" /> 

</RelativeLayout> 

讓我們知道,如果它不能正常工作。 如果您需要多個此佈局,請嘗試以編程方式在運行時創建視圖。

+0

我應該在哪裏準確添加此代碼? :| – CLONER

+0

將其替換爲32的佈局或任何您需要顯示它的地方 – Dexto

+0

我希望您能幫我編寫它的java代碼bro – CLONER