我在調整圖像大小時出現問題TextView。它不會顯示圖標。我想我的圖標大小是這樣的和文本icon with text我不知道我的代碼爲什麼它不會顯示什麼問題。在文本視圖中調整圖標的文字圖標不顯示
<?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="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:background="#eeeeee" android:layout_marginTop="30dp">
<TextView
android:id="@+id/mytxview1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:padding="30dp"
android:scaleType="fitCenter"
android:background="@drawable/button1_style"
android:drawableTop="@drawable/icon1_48dp"
style="@style/Widget.AppCompat.Button.Colored"
android:text = "Button 1"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:padding="30dp"
android:scaleType="fitCenter"
style="@style/Widget.AppCompat.Button.Colored"
android:background="@drawable/button2_style"
android:drawableTop="@drawable/icon2_48dp"
android:tint="#ffffff"
android:text = "Button 2"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:background="#eeeeee" android:layout_marginBottom="20dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:padding="30dp"
android:scaleType="fitCenter"
style="@style/Widget.AppCompat.Button.Colored"
android:drawableTop="@drawable/icon3_48dp"
android:background="@drawable/button3_style"
android:tint="#ffffff"
android:text = "Button 3"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:padding="30dp"
android:scaleType="fitCenter"
style="@style/Widget.AppCompat.Button.Colored"
android:drawableTop="@drawable/icon4_48dp"
android:background="@drawable/button4_style"
android:text = "Button 4"
/>
</LinearLayout>
</LinearLayout>
這裏是我如何調整:
public class MyClass extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
TextView txt1 = (TextView) findViewById(R.id.mytxview1);
Drawable icon = ContextCompat.getDrawable(this,R.drawable.button_style);
icon.setBounds(0, 0, 50, 50);
txt1.setCompoundDrawables(icon,null,null,null);
}
}
預先感謝您。
我想你可以用''drawable''在裏面試試''Button''嗎? –
按鈕然後android:drawableTop? – jemz
是的,你可以試試 –