2014-12-31 2 views
1

나는 안드로이드 개발에 초보자입니다. 내 페이지 요소를 세로로 정렬하려고하지만이를 수행 할 수 없습니다. Java에서 프런트 엔드 레이아웃 컨트롤을 어떻게 사용할 수 있는지 잘 모르겠습니다. 다음과 같이android studio에서 수직으로 다른 요소를 정렬하는 방법은 무엇입니까?

내 main.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:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity"> 

    <!--<View--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="30dip"/>--> 
    <TextView 
     android:text="@string/getVerse" 
     android:layout_width="wrap_content" 
     android:layout_height="100dip" 
     android:textSize="@dimen/header" 
     android:layout_gravity="center_horizontal" 
    /> 

    <!--<View--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="20dip"--> 
    <!--/>--> 
    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/questionSize" 
     android:hint="@string/questionHint" 
     /> 
    <!--<View--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="25dip"--> 
    <!--/>--> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/buttonTextSize" 
     android:text="@string/buttonText"> 
    </Button> 

</LinearLayout> 

페이지는 다음과 같습니다

screenshot of avd 제발 도와주세요!

android:orientation="vertical" 

있는 LinearLayout 부모에 코드를 다음

+0

내 대답보기 @ user3641971 –

+0

@Lal 어떻게 중복 될 수 있습니까? 나는 그 문제를 봤는데 어떤 결과도 얻을 수 없었다. – user3641971

+0

내 코멘트가있는 링크를 참조하십시오. – Lal

답변

3

그냥 LinearLayoutandroid:orientation="vertical" 속성을 사용합니다. Horizontally과 일치하는 요소를 얻게됩니다. 기본값은 Android입니다. 이 도움이

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity"> 

    <!--<View--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="30dip"/>--> 
    <TextView 
     android:text="@string/getVerse" 
     android:layout_width="wrap_content" 
     android:layout_height="100dip" 
     android:textSize="@dimen/header" 
     android:layout_gravity="center_horizontal" 
    /> 

    <!--<View--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="20dip"--> 
    <!--/>--> 
    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/questionSize" 
     android:hint="@string/questionHint" 
     /> 
    <!--<View--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="25dip"--> 
    <!--/>--> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/buttonTextSize" 
     android:text="@string/buttonText"> 
    </Button> 

    </LinearLayout> 

희망 :

그렇게 이후의 코드는 다음과 같습니다!

+0

도움이되었습니다. 고맙습니다. – user3641971

+0

나 같은 것을 가르쳐 줄 수 있습니까? – user3641971

+0

여기에 자습서가 있습니다. http://androidexample.com/Linear_Layout_Basic-_Android_Example/index.php?view=article_discription&aid=72&aaid=96 –

3

추가는 활동에있는 GIF를 표시하려면

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(new GifView(this)); 
    } 

    static class GifView extends View { 
     Movie movie; 
     GifView(Context context) { 
      super(context); 
      File myFile = new File("/sdcard/test.gif"); 
      InputStream fis = null; 
      try { 
       fis = new BufferedInputStream(new FileInputStream(myFile), 
         16 * 1024); 
       fis.mark(16 * 1024); 
      } catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      movie = Movie.decodeStream(fis); 
      Log.e("SS", "movie.duration()" + movie.duration()); 

     } 

     @Override 
     protected void onDraw(Canvas canvas) { 
      try { 
       if (movie != null) { 
        movie.setTime((int) SystemClock.uptimeMillis() 
          % movie.duration()); 
        movie.draw(canvas, 0, 0); 
        invalidate(); 
       } 
      } catch (Exception e) { 
       // TODO: handle exception 
       e.printStackTrace(); 
      } 

     } 
    } 
+0

고마워. 그것은 효과가 있었다. – user3641971

+0

@PsyDuck 당신에게 어떤 질문이 있는지 알려주시겠습니까? – Anjali

+0

아직 없습니다. gif를 보여주기 위해 gif를 표시하는 코드로 내 대답을 업데이트합니다 – Anjali

관련 문제