Reputation: 425
I've tested this with LinearLayout and two TextViews. In both is the same text but with different textSize. I tried to set the height and width in xml and in java and also I tried it with the height 0dp and with weight 1. I don't understand why the second TextView is lower? How can I set them on the same height?
In a later step I need this in a TableLayout with TextViews and EditTexts and it should be like a crossword puzzle. But after it didn't work there, I've tested it with this simple TestApp.
How it looks like: https://i.sstatic.net/in1yL.png
XML File:
<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);
}
Thank you for your help in this matter.
Upvotes: 1
Views: 1352
Reputation: 10959
Put
android:baselineAligned="false"
in your <LinearLayout>
. That will resolve the issue.
Upvotes: 4
Reputation: 885
remove that line : android:textSize="6.5sp" from second textView on layout. it seems the only different things.
Upvotes: 0