Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

Android Prevent Box From Resizing

I am trying to make a four function calculator app. The two blank lines are the numbers involved in the calculations. The issue I have is with the 'result' box. Since I used relativelayout, the placement of everything is relative to the 'result' box. If I first calculate, say, 2+2 and 'result' is 4, it's ok. But if I do 5+5 and 'result' is now 10, a two digit number, everything shifts a little because 'result' has changed. Is there a way to let 'result' change size but keep everything else in place?

Picture of current app UI

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So you may not use Relative Layout. But can we use TableLayout?

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
    android:layout_weight="2"
    android:layout_margin="20dp"
    android:layout_height="0dp"
    android:layout_width="match_parent">
    <EditText
        android:inputType="number"
        android:layout_gravity="bottom"
        android:id="@+id/num_1"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <Space  android:layout_weight="1"
        android:layout_width="0dp"/>
    <EditText
        android:inputType="number"
        android:layout_gravity="bottom"
        android:id="@+id/num_2"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
</TableRow>
<TableRow
    android:layout_weight="1"
    android:layout_margin="20dp"
    android:layout_height="0dp"
    android:layout_width="match_parent">

    <TextView

        android:singleLine="true"
        android:text="Result"
        android:gravity="center"
        android:textSize="24sp"
        android:id="@+id/result"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_column="18" />
</TableRow>
<TableRow
    android:layout_weight="1"
    android:layout_margin="20dp"
    android:layout_height="0dp"
    android:layout_width="match_parent">
    <Button
        android:text="ADD"
        android:id="@+id/add"
        android:layout_width="0dp"
        android:layout_weight="3"
        android:layout_height="wrap_content"/>
    <Space
        android:layout_width="0dp"
        android:layout_weight="2"
        />
    <Button
        android:text="SUBTRACT"
        android:id="@+id/sub"
        android:layout_weight="3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
  </TableRow>
  <TableRow
    android:layout_weight="1"
    android:layout_margin="20dp"
    android:layout_height="0dp"
    android:layout_width="match_parent">
    <Button
        android:text="MULTIPLY"
        android:id="@+id/multi"
        android:layout_width="0dp"
        android:layout_weight="3"
        android:layout_height="wrap_content"/>
    <Space
        android:layout_width="0dp"
        android:layout_weight="2"
        />
    <Button
        android:text="DIVIDE"
        android:id="@+id/divide"
        android:layout_weight="3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
</TableRow>

</TableLayout>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...