80,351
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/poker_bg_displayScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/show_bg"
android:layout_gravity="center"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result_show"
android:background="@drawable/porker_a"
android:layout_gravity="center"/>
<FrameLayout
android:id="@+id/frameLayout_displayScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp">
<ImageView
android:id="@+id/time_bg_displayScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/time_bg"/>
<com.xinhao360.onebyone.SysTool.Time_TextView
android:id="@+id/show_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="60s"
android:layout_gravity="center"/>
</FrameLayout>
</FrameLayout>
</RelativeLayout>
public class DisplayScreen extends RelativeLayout {
private com.xinhao360.onebyone.SysTool.Time_TextView showTime;
private ImageView porker_bg;
private ImageView porker;
private ImageView time_bg;
public DisplayScreen(Context context){
this(context,null);
}
public DisplayScreen(Context context,AttributeSet attributeSet){
super(context,attributeSet);
View view = LayoutInflater.from(context).inflate(R.layout.display_screen,this,true);
porker_bg = (ImageView)findViewById(R.id.poker_bg_displayScreen);
porker = (ImageView)findViewById(R.id.result_show);
showTime = (com.xinhao360.onebyone.SysTool.Time_TextView)findViewById(R.id.show_time);
time_bg = (ImageView)findViewById(R.id.time_bg_displayScreen);
FrameLayout frameLayout = (FrameLayout)findViewById(R.id.frameLayout_displayScreen);
DisplayMetrics dm = getResources().getDisplayMetrics();
//根据当前控件大小改变控件尺寸 扑克背景大小:141*178 (出错的就是这行代码,恳请各位帮忙看看)
RelativeLayout.LayoutParams linearParams =(RelativeLayout.LayoutParams) porker_bg.getLayoutParams(); //取控件textView当前的布局参数
linearParams.height = (dm.heightPixels/415) * 178;// 控件的高强制设成20
linearParams.width = (dm.widthPixels/736) * 141;// 控件的宽强制设成30
porker_bg.setLayoutParams(linearParams); //使设置好的布局参数应用到控件(扑克背景)
//扑克大小:105*160
linearParams.height = (dm.heightPixels/415) * 160;
linearParams.width = (dm.widthPixels/736) * 105;
porker.setLayoutParams(linearParams);
//时间背景大小:89*91
linearParams.height = (dm.heightPixels/415) * 91;
linearParams.width = (dm.widthPixels/736) * 89;
time_bg.setLayoutParams(linearParams);
//位置
linearParams.leftMargin = (dm.heightPixels/415) * 30;
linearParams.topMargin = (dm.widthPixels/736) * 50;
frameLayout.setLayoutParams(linearParams);
}
public String getShowTime(){
return showTime.getText().toString().trim();
}
public void setShowTime(String text){
showTime.setText(text);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/poker_bg_displayScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/show_bg"
android:layout_gravity="center"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result_show"
android:background="@drawable/porker_a"
android:layout_gravity="center"/>
<FrameLayout
android:id="@+id/frameLayout_displayScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp">
<ImageView
android:id="@+id/time_bg_displayScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/time_bg"/>
<com.xinhao360.onebyone.SysTool.Time_TextView
android:id="@+id/show_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="60s"
android:layout_gravity="center"/>
</FrameLayout>
</FrameLayout>
</RelativeLayout>
package com.xinhao360.onebyone.Widget;
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.xinhao360.onebyone.R;
/**
* Created by a on 2017/1/6.
*/
public class DisplayScreen extends RelativeLayout {
private com.xinhao360.onebyone.SysTool.Time_TextView showTime;
private ImageView porker_bg;
private ImageView porker;
private ImageView time_bg;
public DisplayScreen(Context context){
this(context,null);
}
public DisplayScreen(Context context,AttributeSet attributeSet){
super(context,attributeSet);
View view = LayoutInflater.from(context).inflate(R.layout.display_screen,this,true);
porker_bg = (ImageView)findViewById(R.id.poker_bg_displayScreen);
porker = (ImageView)findViewById(R.id.result_show);
showTime = (com.xinhao360.onebyone.SysTool.Time_TextView)findViewById(R.id.show_time);
time_bg = (ImageView)findViewById(R.id.time_bg_displayScreen);
FrameLayout frameLayout = (FrameLayout)findViewById(R.id.frameLayout_displayScreen);
DisplayMetrics dm = getResources().getDisplayMetrics();
//根据当前控件大小改变控件尺寸 扑克背景大小:141*178
//RelativeLayout.LayoutParams linearParams =(RelativeLayout.LayoutParams) porker_bg.getLayoutParams(); //取控件textView当前的布局参数
FrameLayout.LayoutParams linearParams = (FrameLayout.LayoutParams)porker_bg.getLayoutParams();
linearParams.height = (dm.heightPixels/415) * 178;// 控件的高强制设成20
linearParams.width = (dm.widthPixels/736) * 141;// 控件的宽强制设成30
porker_bg.setLayoutParams(linearParams); //使设置好的布局参数应用到控件(扑克背景)
//扑克大小:105*160
FrameLayout.LayoutParams porkerParams = (FrameLayout.LayoutParams)porker.getLayoutParams();
porkerParams.height = (dm.heightPixels/415) * 160;
porkerParams.width = (dm.widthPixels/736) * 105;
porker.setLayoutParams(porkerParams);
//时间背景大小:89*91
FrameLayout.LayoutParams timebgParams = (FrameLayout.LayoutParams)time_bg.getLayoutParams();
timebgParams.height = (dm.heightPixels/415) * 91;
timebgParams.width = (dm.widthPixels/736) * 89;
time_bg.setLayoutParams(timebgParams);
//位置
FrameLayout.LayoutParams frameLayoutParams = (FrameLayout.LayoutParams)frameLayout.getLayoutParams();
frameLayoutParams.leftMargin = (dm.heightPixels/415) * 30;
frameLayoutParams.topMargin = (dm.widthPixels/736) * 50;
frameLayout.setLayoutParams(frameLayoutParams);
}
public String getShowTime(){
return showTime.getText().toString().trim();
}
public void setShowTime(String text){
showTime.setText(text);
}
}
代码简陋,请勿见怪