-3

GravityプロパティをXMLアイテムに適用した後、正しい場所に配置されていないようです。どのようにこれらの問題を固定することができるので、以下の条件が満たされているか?:LinearLayoutアイテムに重大な重力が適用されました

「上に移動」ボタンを
  • 「下に移動」ボタンがであることが必要である画面の上部にあることが必要
    1. 画面の縦中心

      activity_main.xml

    にする画面

  • GridViewニーズの底3210

    UPDATE(akshay_shahaneの提案)

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent" 
        android:layout_gravity="center_vertical" 
        android:orientation="vertical" 
        android:weightSum="100" 
        tools:context=".MainActivity"> 
        <Button 
         android:id="@+id/btn_moveup" 
         android:text="move up" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         android:layout_weight="5" 
         android:onClick="moveup_click" 
         /> 
    
        <GridView 
         android:id="@+id/abslistview_main" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="90" 
         android:layout_gravity="center_vertical" 
         android:numColumns="auto_fit" 
         /> 
    
        <Button 
         android:id="@+id/btn_movedown" 
         android:text="move down" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         android:layout_weight="5" 
         android:onClick="movedown_click" 
         /> 
    </LinearLayout> 
    

    enter image description here

  • +1

    にGridViewの重みを設定する必要があります試してみてください? 0.1、グリッド0.8を上に移動し、0.1に移動するために –

    +0

    @akshay_shahane私はしましたが、GridViewの重力は引き続きプレイしています!それは垂直の中心に行くことはありません! – MacaronLover

    +0

    ルートレイアウトの重力をcenterVerticalに設定しようとしましたか? –

    答えて

    0

    のどちらかがこの

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent" 
        android:orientation="vertical" 
        tools:context=".MainActivity"> 
        <Button 
         android:id="@+id/btn_moveup" 
         android:text="move up" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" /> 
    
        <GridView 
         android:id="@+id/abslistview_main" 
         android:layout_width="match_parent" 
         android:layout_height="0dp" 
         android:numColumns="auto_fit" 
         android:layout_weight="1" 
         /> 
    
        <Button 
         android:id="@+id/btn_movedown" 
         android:text="move down" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         /> 
    </LinearLayout> 
    

    よう0dpまたはグリッドレイアウトをラップするGridLayout 1へとlayout_heightの重みを設定しましたこのような別のコンテナで

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent" 
        android:orientation="vertical" 
        tools:context=".MainActivity"> 
        <Button 
         android:id="@+id/btn_moveup" 
         android:text="move up" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" /> 
    
        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="0dp" 
         android:layout_weight="1"> 
    
         <GridView 
          android:id="@+id/abslistview_main" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center" 
          android:numColumns="auto_fit" /> 
    
        </LinearLayout> 
    
        <Button 
         android:id="@+id/btn_movedown" 
         android:text="move down" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         /> 
    </LinearLayout> 
    

    それはGridLayoutandroid:layout_gravity="center"を使用してセンタリングすることを可能にするため、2番目のオプションが良いだろう。

    0

    この

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent" 
        android:orientation="vertical" 
        android:weightSum="1" 
        tools:context=".MainActivity"> 
        <Button 
         android:id="@+id/btn_moveup" 
         android:text="move up" 
         android:layout_weight="0.1" 
         android:layout_height="0dp" 
         android:layout_width="match_parent" 
         android:layout_gravity="top" 
         /> 
    
        <GridView 
         android:id="@+id/abslistview_main" 
         android:layout_width="match_parent" 
         android:layout_weight="0.8" 
         android:layout_height="0dp" 
         android:layout_gravity="center_vertical" 
         android:numColumns="auto_fit" 
         /> 
    
        <Button 
         android:id="@+id/btn_movedown" 
         android:text="move down" 
         android:layout_weight="0.1" 
         android:layout_height="0dp" 
         android:layout_width="match_parent" 
         android:layout_gravity="bottom" 
         /> 
    </LinearLayout> 
    
    0

    はちょうどあなたが重みを使用していない理由を1

    <?xml version="1.0" encoding="utf-8"?> 
    
    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    tools:context=".MainActivity"> 
    <Button 
        android:id="@+id/btn_moveup" 
        android:text="move up" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:layout_gravity="top" 
        /> 
    
    <GridView 
        android:id="@+id/abslistview_main" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:gravity="center_vertical" 
        android:layout_weight="1" 
        android:layout_gravity="center_vertical" 
        android:numColumns="auto_fit" 
        /> 
    <Button 
        android:id="@+id/btn_movedown" 
        android:text="move down" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:layout_gravity="bottom" 
        /> 
    </LinearLayout> 
    
    関連する問題