![](/img/trans.png)
[英]Is there a way to make 2 Textviews of different layouts the same height?
[英]Set the same height to TextViews with different TextSize
我用LinearLayout和兩個TextView測試了這個。 兩者都是相同的文本但具有不同的textSize。 我嘗試在xml和java中設置高度和寬度,並且我嘗試使用高度為0dp且重量為1.我不明白為什么第二個TextView更低? 如何將它們設置在同一高度?
在后面的步驟中,我需要在帶有TextViews和EditTexts的TableLayout中使用它,它應該像填字游戲。 但是在它沒有用之后,我用這個簡單的TestApp進行了測試。
看起來如何: http : //i.stack.imgur.com/in1yL.png
XML文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:background="@drawable/cell_border"
android:id="@+id/textView1"
android:layout_width="60dp"
android:layout_height="60dp"
android:singleLine = "false"
>
</TextView>
<TextView
android:background="@drawable/cell_border"
android:id="@+id/textView2"
android:layout_width="60dp"
android:layout_height="60dp"
android:singleLine = "false"
android:textSize="6.5sp"
>
</TextView>
</LinearLayout>
Javacode:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView vText = (TextView)findViewById(R.id.textView1);
vText.setText("Dies ist ein Test");
//vText.setWidth(60);
//vText.setHeight(60);
TextView vText2 = (TextView)findViewById(R.id.textView2);
vText2.setText("Dies ist ein Test");
//vText2.setWidth(60);
//vText2.setHeight(60);
}
感謝您對此事的幫助。
放
android:baselineAligned="false"
在你的<LinearLayout>
。 這將解決問題。
刪除該行:android:textSize =“6.5sp”來自布局上的第二個textView。 它似乎是唯一不同的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.