2017-12-08 18 views
-1

私はナビゲーションフラグメントを作成しています。常に存在するボタン(メインボタン)と動的に追加および削除されるボタンがあります。膨らんだボタンの幅と高さが間違っています

私はボタンを膨らませたxmlリソースファイルを持っています。アイコンを変更してフラグメントルートレイアウトに追加します。

ボタンサイズを除いてほとんどすべてが機能します。後のボタンサイズは0です(getWidth()/ getHeight())。

button_navigation.xml

<?xml version="1.0" encoding="utf-8"?> 
<Button xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/navigation_button" 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:background="@drawable/icon_test" 
    android:backgroundTint="@drawable/selector_bar_button"></Button> 

膨張コード

Button butt = (Button) inflater.inflate(R.layout.button_navigation, null, false); 

buttons.add(butt); 
root_view.addView(butt); 

作成インフレータ

public void setParent(MainActivity activity){ 
     parent = activity; 
     inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

個の変数

MainActivity parent; 
LayoutInflater inflater; 

int index; 

ArrayList<Button> buttons; 
Button button_main; 
LinearLayout root_view; 

メインボタンは、button_navigation.xmlとして正確なコードを有しており、断片のレイアウトファイルに起こります。メインボタンのサイズは良いです。

答えて

1

でこれを使用してみてくださいレイアウト内のあなたのボタンを包みます。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<Button 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/nickname_message" 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:text="adawd awdaw" 
    android:textSize="18sp" 
    android:textStyle="bold" /> 

その後、実行時にそれを追加します。

linearLayout.addView(LayoutInflater.from(this).inflate(R.layout.item_layout,null)); 
+0

作品をそれをしないしたいのですが、[OK]をthatsの。 –

+0

同様の問題を抱えている人は誰でも、私はインフレータでライナーレイアウトを取得し、そのIDを介してボタンを取得し、ライナーレイアウトからそのボタンを削除して、 –

0

は、Javaコードbutton.setLayoutParams (new LayoutParams(60,60);

+0

は、私は私がそれを行うことができます知っているが、私は、レイアウトからボタンを取得する必要がありますが、私は、...コードから –

関連する問題