2016-06-24 14 views
-3

これは、コードリニアレイアウトが正しく構成要素を示していない

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:text="Email:" 
     android:textSize="30dp" 
     android:paddingLeft="0dp" 
     android:paddingTop="10dp"/> 

    <EditText 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" 
     android:singleLine="true" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Login" 
     android:paddingTop="10dp"/> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="100dp" 
      android:text="Home" /> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:text="About" /> 

    </LinearLayout> 
</LinearLayout> 

私はアンドロイドのスタジオでレイアウトを練習したいとコードを実装しながら、私はエラーを取得しています。 これは、携帯電話の画面外になったテキストです:

enter image description here

はなぜ青い箱は、携帯電話の画面の外に行くのですか?

enter image description here

+0

まず、アンドロイドでデザインを作成するための基礎を学ぶ必要があります。どこでもビューの幅と高さをハードコーディングしています。必要がない場合は、幅と高さをハードコードするべきではありません。 –

答えて

1

あなたはそれぞれのlayout_widthを設定している自分を見ます。使用可能な画面の最大幅があることを知っておく必要があります。さらに、ボタンの幅をmatch_parentに設定すると、隣接するビューの幅が固定されている場合には適切ではありません。 LinearLayoutを使用している場合は、layout_weight属性を試してください。遊んで実験してみてください。例えば

<?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="horizontal"> 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" 
    android:paddingLeft="0dp" 
    android:paddingTop="10dp" 
    android:text="Email:" 
    android:textSize="30dp" /> 

<EditText 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="4dp" 
    android:layout_weight="2" 
    android:singleLine="true" /> 

<Button 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" 
    android:paddingTop="10dp" 
    android:text="Login" /> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:text="Home" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:text="About" /> 

</LinearLayout> 
</LinearLayout> 
+0

私もmatch_parentで試してみましたが、動作していません – BHAGAT

+0

あなたは 'match_parent'を使うべきではありません – Marat

+0

私はアップロードした写真を見ますか? – BHAGAT

2

あなたが適切にレイアウトを設定していません。 layout weightを設定せずに、parentView(LinearLayout)のchildViewを水平に整列させました。 documentation on LinearLayoutをお読みください。ただし、レイアウトを修正するには、別のコンテナを追加してレイアウトの最初の行を保持し、2番目の行を画面に表示させることができます。現在のコードには、他のビューが表示されないようにする単一の行のすべてのchildViewが含まれています。以下のコードを試してください:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:text="Email:" 
      android:textSize="30dp" 
      android:paddingLeft="0dp" 
      android:paddingTop="10dp"/> 

     <EditText 
      android:layout_width="150dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="4dp" 
      android:singleLine="true" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Login" 
      android:paddingTop="10dp"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="100dp" 
      android:text="Home" /> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:text="About" /> 

    </LinearLayout> 
</LinearLayout> 
+0

そのように多くのyaarに感謝します..... – BHAGAT

関連する問題