如果我android:textSize="?android:attr/textAppearanceLarge"在我的xml中使用我的应用程序崩溃.我不想给出硬编码文本大小,因为我必须为不同的屏幕尺寸创建create xml,或者我必须在运行时管理文本大小.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title"
android:textSize="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/saveOnDialog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/save"
style="?android:attr/buttonBarButtonStyle"
android:textSize="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/cancelOnDialog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/cancel"
style="?android:attr/buttonBarButtonStyle"
android:textSize="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是Log.e输出 -
06-26 11:46:27.439: E/AndroidRuntime(1731): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
06-26 11:46:27.439: E/AndroidRuntime(1731): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-26 11:46:27.439: E/AndroidRuntime(1731): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
06-26 11:46:27.439: E/AndroidRuntime(1731): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
06-26 11:46:27.439: E/AndroidRuntime(1731): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-26 11:46:27.439: E/AndroidRuntime(1731): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-26 11:46:27.439: E/AndroidRuntime(1731): …Run Code Online (Sandbox Code Playgroud) 我正在使用优先级队列来根据cgpa对学生列表进行排序,这是一个双倍值.如果我将它作为整数而不是它正常工作或者如果我将字段名称添加为字符串并基于字符串排序那么它也可以正常工作.
public class MainClass {
public static void main(String[] args) {
// comparator class to sort the student on basis of cgpa.
Comparator<Student> studentComparator = new Comparator<Student>() {
@Override
public int compare(Student s1, Student s2) {
if (s1.getCgpa() < s2.getCgpa())
return 1;
else if (s1.getCgpa() > s2.getCgpa())
return -1;
else
return 0;
}
};
Scanner in = new Scanner(System.in);
int totalEvents = 8;
PriorityQueue<Student> studentList = new PriorityQueue<>(totalEvents, studentComparator);
// adding value in to priority queue by taking input from …Run Code Online (Sandbox Code Playgroud)