[英]how to set background image in Linear layout dynamically using Parser in android
[英]Android: how to set background image in table layout
我正在使用tablelayout来显示sqlite db中的项目。 我为表布局设置了backgrpund图像,但是该图像显示在文本下方,我需要将图像显示回文本,而不是下方,即,我需要将图像框架设置为0,0。 现在我用
.setbackgroundresources(r.drawable.imagename)
请指导我,我必须以编程方式为表布局添加背景图像
如果要为布局设置背景资源,并且图像显示在布局本身下方(即,所有组件下方),则可能没有将背景资源添加到正确的布局中。
但是由于您并未真正提供太多信息,所以情况可能并非如此。
可能是您的图像实际上比表格本身小很多,而不是扩大到表格的大小,而是保持在其固定大小(可能会在布局中居中)吗?
尝试将表格的背景设置为固定的颜色(即view.setBackgroundColor(Color.BLACK);)进行测试。 如果整个表都按预期填充,则可能与您使用的图像有关。
如果颜色仅填充图像资源之前的相同区域,则可能是我首先想到的是未将资源添加到正确布局的地方。
然后尝试在.xml文件中放置一个表布局的外部布局线性布局,然后设置该线性布局的背景,例如
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bkg1">
<TableLayout
android:id="@+id/linearLayout1_tblLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/linearLayout1_tblLayout1_tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
......
</TableRow>
</TableLayout>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.