我的Android应用布局不会在不同的设备合身? [英] My android application layout does not fit well on different devices?
问题描述
下面是我的应用程序是什么样的快照
Here are snapshots of what my application looks like
它适合在某些设备上,而不是对他人:
It fits on some devices and not on others:
正如你所看到的,水平它适合真的很好不管。我怎样才能确保它完全适合,以及垂直?
As you can see, horizontally it fits really well no matter what. How can I make sure it fits perfectly as well vertically?
下面是我的XML code:
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableRow0"
android:layout_width="match_parent"
android:weightSum="1" >
<TextView
android:id="@+id/ResultText"
android:layout_width="0dp"
android:gravity="right"
android:background="#AAAAAA"
android:layout_weight="1"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_height="fill_parent"
android:maxLines="3"
android:scrollbars="vertical" />"
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:weightSum="1" >
<TextView
android:id="@+id/InputText"
android:layout_width="0dp"
android:background="#BBBBBB"
android:gravity="right"
android:textColor="#FFFFFF"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:textSize="20sp"
android:maxLines="3"
android:scrollbars="vertical" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:weightSum="1" >
<TextView
android:id="@+id/memoryStatText"
android:layout_width="0dp"
android:background="#BBBBBB"
android:gravity="right"
android:textColor="#FFFFFF"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:textSize="15sp"
android:maxLines="3"
android:scrollbars="vertical" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.1"
android:weightSum="1" >
<Button
android:id="@+id/buttonMAdd"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="M+"
android:onClick="ProcessInput"
android:layout_height="wrap_content"
android:gravity="fill" />
<Button
android:id="@+id/buttonMRemove"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="M-"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonMC"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="MC"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonMR"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="MR"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonClearAll"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="C"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonDel"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="del"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonPower"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:textSize="12sp"
android:text="pow"
android:gravity="fill"
android:onClick="ProcessInput"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonFactorial"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.166"
android:text="x!"
android:layout_height="match_parent"
android:onClick="ProcessInput"
android:gravity="fill" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.1"
android:weightSum="1" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="1"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="2"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="3"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="4"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="5"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="6"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="7"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="8"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="9"
android:onClick="ProcessInput"
android:gravity="fill"
android:layout_height="match_parent" />"
<Button
android:id="@+id/button0"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="0"
android:onClick="ProcessInput"
android:gravity="fill"
android:layout_height="match_parent" />
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:weightSum="1"
android:layout_weight="0.1" >
<Button
android:id="@+id/buttonAdd"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="+"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonSubtract"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="-"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonDivide"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="/"
android:onClick="ProcessInput"
android:gravity="fill"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonMultiply"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="x"
android:onClick="ProcessInput"
android:gravity="fill"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonPeriod"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="."
android:onClick="ProcessInput"
android:gravity="fill"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonSign"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="±"
android:onClick="ProcessInput"
android:gravity="fill"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonEqual"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="="
android:onClick="ProcessInput"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonPercent"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:gravity="fill"
android:text="%"
android:layout_height="match_parent"
android:onClick="ProcessInput" />
<Button
android:id="@+id/buttonLog10"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="log"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonLoge"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.1"
android:text="ln"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:weightSum="1"
android:layout_weight="0.1" >
<Button
android:id="@+id/buttonSin"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:gravity="fill"
android:text="sin"
android:onClick="ProcessInput"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonCos"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:gravity="fill"
android:text="cos"
android:onClick="ProcessInput"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonTan"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:gravity="fill"
android:text="tan"
android:onClick="ProcessInput"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonSinInverse"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:textSize="8sp"
android:gravity="fill"
android:text="@string/sin_inv"
android:onClick="ProcessInput"
android:layout_height="match_parent"/>
<Button
android:id="@+id/buttonCosInverse"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:gravity="fill"
android:textSize="8sp"
android:text="@string/cos_inv"
android:onClick="ProcessInput"
android:layout_height="match_parent"/>
<Button
android:id="@+id/buttonTanInverse"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:gravity="fill"
android:textSize="8sp"
android:text="@string/tan_inv"
android:onClick="ProcessInput"
android:layout_height="match_parent"/>
<Button
android:id="@+id/buttonSquare"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="sqr"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
<Button
android:id="@+id/buttonSquareRoot"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="0.125"
android:text="sqrt"
android:onClick="ProcessInput"
android:layout_height="match_parent"
android:gravity="fill" />
</TableRow>
</TableLayout>
</ScrollView>
即使我写不同的屏幕布局不同的XML,我不认为我可以改变任何东西。它的,因为我不能改变任何东西。我不打算添加更多按钮或类似的东西。
另外,如果我使用DP设置按钮,textviews等,以准确的尺寸它仍然是一个问题,因为那将是设备特定的。
Even if i write different XML for different screen layouts, i don't think i can change anything. Its because i can't change anything. I am not going to add more buttons or something like that. Also if i set Buttons, textviews etc. to an accurate size using dp it would still be a problem because then it would be device specific.
我在纵向模式下9行7景观mode.I想打电话之前计算的高度和屏幕的宽度。的setContentView(R.layout.main);然后计算肖像模式和横向模式高度/ 7总高度/ 9。谁能告诉我如何进行?那就是如何动态地知道,如果布局是横向或纵向,以及如何分配高度行。
I have 9 rows in portrait mode and 7 in landscape mode.I was thinking to calculate height and width of screen before calling. setContentView(R.layout.main); Then calculate total height/9 for portrait mode and height/7 for landscape mode. Can anyone tell me how to proceed?That is how to know dynamically if layout is landscape or portrait , and how to assign height to rows.
现在我有这个
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
double height = displaymetrics.heightPixels/9;
double width = displaymetrics.widthPixels/7;
int Orientation = getResources().getConfiguration().orientation;
if(Orientation == Configuration.ORIENTATION_LANDSCAPE)
{
Set height of all rows.
}
如何设置所有行的高度。
How to set height of all rows.
推荐答案
根据您的其他职位,既然你有不同的布局,在code,可确定与下列code方向:
Based on your other post, since you have different layouts, in the code you can determine orientation with the following code:
int orientation = getResources().getConfiguration().orientation
if(orientation == Configuration.ORIENTATION_LANDSCAPE)
//landscape code...
else
//portrait code...
我张贴在两个线程都适合你。
I posted in both threads for you.
这篇关于我的Android应用布局不会在不同的设备合身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!