2014-08-29 66 views
0

我一直试图解决这一整天无济于事。我有一个简单的测验应用程序,它询问代码段的输出,但文本和代码离左边太远。我试图通过更改边距来修复它,但是它弄乱了配色方案。在android布局中的文本被截断,如何将文本向右移?

关于它的任何想法?

继承人的XML:

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#1D6A9E" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#000000" /> 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.01" /> 
    <TextView 
     android:id="@+id/textView67" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     android:layout_weight="0.01" 
     android:textSize="16dp"/> 

    <RadioGroup 
     android:id="@+id/radioGroup1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     android:layout_weight="0.04" > 

     <RadioButton 
      android:id="@+id/radio0" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:textSize="20dp" 
      android:text="RadioButton" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="match_parent" 
      android:layout_height="31dp" /> 

     <RadioButton 
      android:id="@+id/radio1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20dp" 
      android:text="RadioButton" /> 
    </RadioGroup> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#CD211F" 
     android:text="@string/str_next" /> 
</LinearLayout> 

</RelativeLayout> 

这里的类:

package com.interviewme; 
/** 
* This class creates and holds the database table and its values 
* 
*/ 

/** 
* This class creates and holds the database table and its values 
* 
*/ 


import java.util.ArrayList; 
import java.util.List; 
import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 


public class DbHelper11 extends SQLiteOpenHelper { 

    //setting up database 
    private static final int DATABASE_VERSION = 1; 
    // Creating the database name 
    private static final String DATABASE_NAME = "InterdjvniddjegdppddfdwgFdFApp"; 
    // Creating the tables namef 
    private static final String TABLE_QUEST11 = "quest"; 
    // Creating the columns names 
    private static final String KEY_ID = "id"; 
    private static final String KEY_QUES = "question"; 
    private static final String KEY_CODE= "code"; 
    private static final String KEY_ANSWER = "answer"; //This string will be the answer 
    private static final String KEY_OPTA= "opta"; //String for option A 
    private static final String KEY_OPTB= "optb"; //String for option B 

    private SQLiteDatabase dbase; 
    public DbHelper11(Context context) { 
     super(context, DATABASE_NAME, null, DATABASE_VERSION); 
    } 

    //making database 
    @Override 
    public void onCreate(SQLiteDatabase db) { 
     dbase=db; 
     String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST11 + " (" 
       + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUES 
       + " TEXT, " + KEY_CODE+ " TEXT, " + KEY_ANSWER+ " TEXT, "+KEY_OPTA +" TEXT, " 
       +KEY_OPTB +" TEXT)"; 
     db.execSQL(sql);   
     addQuestions11(); 
     //db.close(); 
    } 
    private void addQuestions11() 

    //adding the questions to the database 

    { 
     Question11 q1=new Question11("Which of these will cause a java programming error?", 
       "A) float[ ] f = new float(3); "+ 
       "                  "+ 
       " B)float f3[ ] = new float[3];",        
       " A) float[ ] f = new float(3);", 
       " B)float f3[ ] = new float[3];", 
       " A) float[ ] f = new float(3);"); 



     this.addQuestion11(q1); 



     Question11 q2=new Question11("2. What will be the output of the program? ", 
       "public class Pet"+ 
       "                   "+ 
       " {                  "+ 
       "                  "+ 
       " public static void main(String args[])        "+ 
       "                  "+ 
       " {                 "+ 
       "                  "+ 
       " class Dog        "+ 
       "                   "+ 
       " {                  "+ 
       "                   "+ 
       " public int i = 3;              "+ 
       " }                   "+ 
       " Object o = (Object)new Dog();           "+ 
       "                   "+ 
       " Dog dog = (Dog)o;               "+ 
       "                    "+ 
       " System.out.println('i = ' + dog.i);           "+ 
       " } ", 

       "i = 3", "compilation fails", "i = 3"); 



     this.addQuestion11(q2); 
     Question11 q3=new Question11("What is the output of the program?", 
       "for(int i = 0; i < 3; i++)             "+ 
       "                   "+ 
       " {                  "+ 
       "                   "+ 
       " switch(i)                 "+ 
       "                   "+ 
       " {                  "+ 
       "                   "+ 
       " case 0: break;               "+ 
       "                   "+ 
       " case 1: System.out.print('one ');           "+ 
       "                   "+ 
       " case 2: System.out.print('two ');           "+ 
       "                   "+    
       " case 3: System.out.print('three ');          "+ 
       "                   "+ 
       " }                  "+ 
       "                   "+ 
       " }                  "+ 
        " }                  "+ 
        "                   "+ 
        "System.out.println('done');            ", 
        "Done", 
        "One two three done", 
        "One two three done"); 
     this.addQuestion11(q3); 
     Question11 q4=new Question11("What will be the output of the program?", 
       "int i = O;                 "+ 
       "                   "+ 
       " while(1)                 "+ 
       "                   "+ 
       " {                  "+ 
       "                   "+ 
       " if(i == 4)                "+ 
       " {                  "+ 
       "                   "+ 
       " break;                 "+ 
       " }                     "+ 
       " ++i;                  "+ 
       "  }                  "+ 
       " System.out.println('i = ' + i);            ", 
       "i=4", 
       "compilation fails", 
       "compilation fails"); 
     this.addQuestion11(q4); 
     Question11 q5=new Question11("What will be the output of the program?", 
       "String a = 'newspaper';              "+ 
       "                   "+ 
       " a = a.substring(5,7);              "+ 
       "                   "+ 
       " char b = a.charAt(1);              "+ 
       "                   "+ 
       " a = a + b;                "+ 
       "                   "+ 
       " System.out.println(a);             ", 
       "app", 
       "apa", 
       "app"); 

     this.addQuestion11(q5); 

     Question11 q6=new Question11("6. What is the value of num after this code is executed?", 
       "Int num = 0;                 "+ 
       "                      "+ 
       " Int num2 = 12;                  "+ 
       "                      "+ 
       " While(num< num2)                  "+ 
       "                        "+ 
       "  {                    "+ 
       " num= numer+1;                   "+ 
       "   }                   ", 
       "5", 
       "12", 
       "12"); 

     this.addQuestion11(q6); 

     Question11 q7=new Question11("7. Look at the following piece of code."+ 
        " What will be assigned to the variable if the code is executed?", 
        "String string = new String (“PINK”);             "+ 
        "                      "+ 
        " Char fourthChar = string.CharAt(4);             ", 
        "Throws " + 
        "StringIndexOutofBoundsException", 

        "K", 
        "Throws StringIndexOutofBoundsException"); 

     this.addQuestion11(q7); 


     Question11 q8=new Question11("This code will generate a random number between what range?", 
         "double randNumber = (int) (Math.random() * 40 + 20);", 
         "20-60", 
         "0-40", 
         "20-60"); 

     this.addQuestion11(q8); 



     Question11 q9=new Question11("9. What would the following code snippet output?", 
         "int sum = 5;                   "+ 
         "                      "+ 
         " sum = sum + sum *5/2;                 "+ 
         "                      "+ 
         " System.out.println(sum);                ", 

         "17", 
         "17.5", 
         "17"); 

     this.addQuestion11(q9); 


     Question11 q10=new Question11("Analyze the following code", 
        "Circle c = new Circle (5);                 "+ 
         "                       "+ 
         " Cylinder c = cy;                   ", 

         "The code has a compile error", 
         "The code is OK", 
         "The code has a compile error"); 


     this.addQuestion11(q10); 

     Question11 q11 = new Question11 ("Does the return statement in the following method"+ 
         " cause compile errors?", 
         "public static void main(String[] args) {              "+ 
         "                        "+ 
         " int max = 0;                    "+ 
         "                        "+ 
         " if (max != 0)                    "+ 
         " System.out.println(max);                 "+ 
         "                        "+ 
         " else                       "+ 
         "                        "+ 
         " return;                      "+ 
         "  }                       ", 
         "Yes", 
         "No", 
         "Yes"); 

     this.addQuestion11(q11); 
     Question11 q12 = new Question11 (" What is the output of the following code?", 
         "int z = 0;                    "+ 
           "                       "+ 
         " if (z < 4) {                     " + 
         "                       "+ 
         " z = z + 1;                    "+ 
         "                       "+ 
         " }                       "+ 
         "                       "+ 
         " System.out.println('z is ' + z);               ", 
         "z is 1", 
         "z is 2", 
         "z is 1"); 

     this.addQuestion11(q12); 


     Question11 q13 = new Question11 (" Assume x = 6. Which of the following is true?", 
         "                        ", 
         "!(x == 6)", 
         " x != 5", 
         " x != 5"); 

     this.addQuestion11(q13); 

     Question11 q14 = new Question11 (" What is the output of the following code:", 
         "public class Test {                   "+ 
         "                        "+ 
         " public static void main(String[] args) {             "+ 
          "                        "+ 
         " Object o1 = new Object();                 "+ 
         "                        "+ 
         " Object o2 = new Object();                 "+ 
         "                        "+ 
         " System.out.print((o1 == o2) + ' ' + (o1.equals(o2)));          ", 
         "False True", 
         "False False", 
         "False False"); 

     this.addQuestion11(q14); 


     Question11 q15 = new Question11 (" Suppose an ArrayList list contains {"+ 
       "'blue' 'blue' 'pink'}. What is list after the following code?", 
       "String element = 'blue';                  "+ 
       "                        "+ 
       " for (int i = 0; i < list.size(); i++)              "+ 
       "                        "+ 
       " if (list.get(i).equals(element))               "+ 
       "                        "+ 
       " list.remove(element);                  ", 
       "{'blue', 'pink'}", 
       "{'blue','blue', 'pink'}", 
       "{'blue', 'pink'}"); 

     this.addQuestion11(q15); 


     Question11 q16 = new Question11 (" What is the output of the following code?", 
       "char ch = 'G';                      "+ 
       "                         "+ 
       " if (ch >= 'A' && ch <= 'Z')                  "+ 
       "                         "+ 
       " System.out.println(ch);                   ", 
       "g", 
       "G", 
       "g"); 


     this.addQuestion11(q16); 


     Question11 q17 = new Question11 ("What are the base cases in the following recursive method?", 
       "public static void example(int n) {                 "+ 
       "                         "+ 
       " if (n > 0) {                      "+ 
       "                         "+ 
       " System.out.print(n % 10);                   "+ 
       "                         "+ 
       " example(n/10);                     "+ 
       "                         ", 
       "n <= 0", 
       "n > 0", 
       "n <= 0"); 


     this.addQuestion11(q17); 
     Question11 q18 = new Question11 ("18. Study the following code:", 
       "public class Example {                     "+ 
       "                          "+ 
       " public static void main(String[] args) {                "+ 
       "                          "+ 
       " Number y = new Integer(3);                   "+ 
       "                          "+ 
       " System.out.println(y.intValue());                  "+ 
       "                          "+ 
       " System.out.println(y.compareTo(new Integer(4)));              "+ 
       "                           "+ 
       " }                         ", 
       "The program has a compile error because y does not have the compareTo method", 
       "The program compiles and runs fine", 
       "The program has a compile error because y does not have the compareTo method"); 

     this.addQuestion11(q18); 


     Question11 q19 = new Question11 ("What exception type will the following code throw?", 
       "public class Example {                      "+ 
       "                            "+ 
       " public static void main(String[] args) {                 "+ 
       "                            "+ 
       " System.out.println(1/0);                     "+ 
       " }                            "+ 
       "                            "+ 
       "}                            ", 
       "ClassCastException", 
       "ArithmeticException", 
       "ArithmeticException"); 


     this.addQuestion11(q19); 

     Question11 q20 = new Question11 ("20. HashMap is an interface and Map is the class "+ 
       "that implements HashMap","CODE", "True", "False", "True"); 
     this.addQuestion11(q20); 

    } 
    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldV, int newV) { 
     //drop the table if it all ready exists 
     db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUEST11); 
     // Create tables again 
     onCreate(db); 
    } 
    // Method to add the questions from the "Question" class 
    public void addQuestion11(Question11 quest) { 

     ContentValues values = new ContentValues(); 
     values.put(KEY_QUES, quest.getQUESTION()); 
     values.put(KEY_CODE, quest.getCODE()); 
     values.put(KEY_ANSWER, quest.getANSWER()); 
     values.put(KEY_OPTA, quest.getOPTA()); 
     values.put(KEY_OPTB, quest.getOPTB()); 

     // Creating a row with null values 
     dbase.insert(TABLE_QUEST11, null, values);  
    } 

    //Creating an array to hold the questions 
    public List<Question11> getAllQuestions11() { 
     List<Question11> questionList11 = new ArrayList<Question11>(); 
     // Select All Query 
     String selectQuery = "SELECT * FROM " + TABLE_QUEST11; 
     dbase=this.getReadableDatabase(); 

     //creating the cursor object 
     Cursor cursor = dbase.rawQuery(selectQuery, null); 
     // Creating a looping to go through all rows and adding to the list 
     if (cursor.moveToFirst()) { 
      do { 
       Question11 quest11 = new Question11(); 
       quest11.setID(cursor.getInt(0)); 
       quest11.setQUESTION(cursor.getString(1)); 
       quest11.setCODE(cursor.getString(2)); 
       quest11.setANSWER(cursor.getString(3)); 
       quest11.setOPTA(cursor.getString(4)); 
       quest11.setOPTB(cursor.getString(5)); 

       questionList11.add(quest11); 
      } while (cursor.moveToNext()); 
     } 
     // return quest list 
     return questionList11; 
    } 
    public int rowcount() 
    { 
     int row=0; 
     String selectQuery = "SELECT * FROM " + TABLE_QUEST11; 
     SQLiteDatabase db = this.getWritableDatabase(); 
     Cursor cursor = db.rawQuery(selectQuery, null); 
     row=cursor.getCount(); 
     return row; 
    } 

}

(IVE试图移动在dbHelper类laoyout轮过,但没” t有所作为!

回答

1

如果textview处于线性布局,则使用

android:layout_gravity = "Right" 

如果相对布局使用

android:layout_alignParentRight="true" 

注销head..put这些代码在TextView的..,看看它是否works..let我知道这是你在寻找什么 感谢

0

如果你的文字是非常大的,你可以尝试使用选取框效果:

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="marquee" 
    android:singleLine="true" /> 
0

使用android:layout_gravity在线性布局中对齐TextView。