Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以编程方式将文本覆盖在framelayout中的imageview上-Android_Android_Textview_Imageview_Android Framelayout - Fatal编程技术网

以编程方式将文本覆盖在framelayout中的imageview上-Android

以编程方式将文本覆盖在framelayout中的imageview上-Android,android,textview,imageview,android-framelayout,Android,Textview,Imageview,Android Framelayout,我试图在布局中心和底部的framelayout中的图像上实现文本视图,如图所示: 你所需要做的就是让textview像这样填充父视图 LayoutParams layoutParamsText= new LayoutParams(LayoutParams.FILL__PARENT, LayoutParams.FILL_PARENT); 当您将重力设置为textview时,意味着您正在告诉textview其子对象的位置。但是由于文本视图只有文本的大小,因此重力不会显示任何差

我试图在布局中心和底部的framelayout中的图像上实现文本视图,如图所示:


你所需要做的就是让textview像这样填充父视图

LayoutParams layoutParamsText= new LayoutParams(LayoutParams.FILL__PARENT, 
        LayoutParams.FILL_PARENT); 
当您将重力设置为textview时,意味着您正在告诉textview其子对象的位置。但是由于文本视图只有文本的大小,因此重力不会显示任何差异。因此,只需创建textview来填充父对象

但我认为RelativeLayout比FrameLayout更适合于此。使用RelativeLayout这就是它的外观

RelativeLayout rLayout = new RelativeLayout(this);
LayoutParams rlParams = new LayoutParams(LayoutParams.FILL_PARENT
        ,LayoutParams.FILL_PARENT); 
rLayout.setLayoutParams(rlParams);

ImageView image= new ImageView(this); 
image.setImageResource(R.drawable.icon);    
image.setLayoutParams(rlParams);

RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
        (LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
TextView text=new TextView(this); 
text.setText("GOLDEN Gate"); 
text.setTextColor(Color.WHITE);                            
text.setTypeface(Typeface.DEFAULT_BOLD);
text.setLayoutParams(tParams);

rLayout.addView(image);
rLayout.addView(text);
setContentView(rLayout);

您可能希望尝试使用RelativeLayout作为容器,而不是FrameLayout。这样,您就可以将覆盖文本放置在任何需要的位置。您应该在RelativeLayout中将以下内容分配给您的TextView:

android:layout_alignParentBottom="true" and android:layout_centerInParent="true"
然后可以使用边距微调放置

RelativeLayout rLayout = new RelativeLayout(this);
LayoutParams rlParams = new LayoutParams(LayoutParams.FILL_PARENT
        ,LayoutParams.FILL_PARENT); 
rLayout.setLayoutParams(rlParams);

ImageView image= new ImageView(this); 
image.setImageResource(R.drawable.icon);    
image.setLayoutParams(rlParams);

RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
        (LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
TextView text=new TextView(this); 
text.setText("GOLDEN Gate"); 
text.setTextColor(Color.WHITE);                            
text.setTypeface(Typeface.DEFAULT_BOLD);
text.setLayoutParams(tParams);

rLayout.addView(image);
rLayout.addView(text);
setContentView(rLayout);
android:layout_alignParentBottom="true" and android:layout_centerInParent="true"