Моя деятельность fullscreen.xml имеет этот отрывок, который работает именно так, как я хочу, производя вывод с десятичными знаками выровненную:Как выровнять эти цифры по десятичной форме в Android?
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|top"
android:gravity="center">
<TextView
android:layout_width="140dp"
android:layout_height="24dp"
android:text="-0.123"
android:id="@+id/acc_x"
android:layout_gravity="center_horizontal|top"
android:textColor="#ffffff"
android:gravity="center_vertical|end"
android:layout_margin="0dp"
style="@style/Base.TextAppearance.AppCompat.Large" />
<TextView
android:layout_width="140dp"
android:layout_height="24dp"
android:text="0.123"
android:id="@+id/acc_y"
android:layout_gravity="center_horizontal|top"
android:textColor="#ffffff"
android:gravity="center_vertical|end"
android:layout_margin="0dp"
style="@style/Base.TextAppearance.AppCompat.Large" />
<TextView
android:layout_width="140dp"
android:layout_height="24dp"
android:text="99.123"
android:id="@+id/acc_z"
android:layout_gravity="center_horizontal|top"
android:textColor="#ffffff"
android:gravity="center_vertical|end"
android:layout_margin="0dp"
style="@style/Base.TextAppearance.AppCompat.Large" />
<TextView
android:layout_width="140dp"
android:layout_height="24dp"
android:text="99.123"
android:id="@+id/acc_T"
android:layout_gravity="center_horizontal|top"
android:textColor="#ffffff"
android:gravity="center_vertical|end"
android:layout_margin="0dp"
style="@style/Base.TextAppearance.AppCompat.Large" />
</LinearLayout>
Но когда я рассчитать число и заполнить те же текстовые поля с этим код, изменения выравнивания:
x = -0.123f;
text = (TextView)findViewById(R.id.acc_x);
text.setText(String.format("%-8.3f",x));
y = 0.123f;
text = (TextView)findViewById(R.id.acc_y);
text.setText(String.format("%-8.3f",y));
z = 99.123f;
text = (TextView)findViewById(R.id.acc_z);
text.setText(String.format("%-8.3f",z));
T = 0;
text = (TextView)findViewById(R.id.acc_T);
text.setText(String.format("%-8.3f",T));
Что я могу сделать, чтобы выравнивание по десятичной точке было запланировано?
Вот мой build.gradle в случае, если имеет значение:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.app001"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
Одна вещь, вы не должны указать точные размеры для TextViews, вы можете просто использовать «wrap_content» для их layout_height и layout_width и использование маржи/дополнения для позиционирования. – jmcdonnell40
Используйте таблицу с тремя столбцами, имеющими текстовое представление. Разделите свою строку на две на. и задайте предварительно десятичную часть в первом столбце с гравитационным правом, a. во втором столбце и после десятичной части в третьем столбце с гравитацией слева. Хороший выбор цвета кстати. –