我正在使用自定义字体到我的GridView,它完美应用但我想改变项目中显示的文本大小。
我想以两种方式更改GridView文本的大小,以编程方式和如何在XML文件中执行它,因为我知道我不知道如何用XML文件中的文本填充GridView的项目不使用编程。
XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/prenomgarc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:fitsSystemWindows="true"
android:tag="big_screen"
tools:context=".Activities.Menu.BBEnRoute.Prenom.PrenomGarcActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#91d0f0"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@drawable/toolbar_garc"
android:scrollbars="none"
android:weightSum="1"
app:popupTheme="@style/AppTheme.PopupOverlay">
<Button
android:id="@+id/b_back"
android:layout_width="19dp"
android:layout_height="35dp"
android:background="@drawable/button_back" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ImageView
android:layout_width="470dp"
android:layout_height="610dp"
android:layout_below="@id/appbar"
android:layout_centerHorizontal="true"
android:layout_marginBottom="90dp"
android:layout_marginTop="75dp"
android:background="@drawable/prenom_back" />
<GridView
android:id="@+id/grid_view"
android:layout_width="470dp"
android:layout_height="610dp"
android:layout_below="@id/appbar"
android:layout_centerHorizontal="true"
android:layout_marginBottom="90dp"
android:layout_marginTop="75dp"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="4"
android:paddingTop="15dp">
</GridView>
Java文件
public class PrenomGarcActivity extends AppCompatActivity {
Button b_back;
TextView a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,vv,w,x,y,z;
GridView gridview;
static final String[] names = new String[] {
"Adam","Adel","Adil","Aissa","Amin","Amir","Assil", " ", " ",
"Bachir","Badis","Bassim","Bilell"," "," ",
"Chafik","Chahid","Chaker","Chams","Chawki"," ",
"Djamel","Djalil"," ",
"Fares"," "," ",
"Ghani"," "," ",
"Habib", "Hafid","Hakim","Halim","Hamid","Hani",
"Idriss","Imed","Ismail",
"Jabir"," "," ",
"Kader","Kamel","Karim","Khaled","Khalill"," ",
"Lotfi"," ", " ",
"Mahboub","Mahfoud","Mahmoud","Malik","Mourad"," ",
"Nabil","Nacer","Nadjib","Nassim","Nazim"," ",
"Omar","Othmane","Oussama",
"Rachid","Ramzi","Raouf","Rayan","Reda"," ",
"Sabri","Salim","Sami",
"Taoufik"," "," ",
"Walid","Waiil","Wassim","Wafid"," "," ",
"Yacine"," "," ",
"Zahi","Zakaria","Zoubair",
" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "
," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",
" "," "," "};
static final String[] namesBigScreen = new String[] {
"Adam","Adel","Adil","Aissa","Amin","Amir","Assil", " ",
"Bachir","Badis","Bassim","Bilell",
"Chafik","Chahid","Chaker","Chams","Chawki"," "," "," ",
"Djamel","Djalil"," "," ",
"Fares"," "," "," ",
"Ghani"," "," "," ",
"Habib", "Hafid","Hakim","Halim","Hamid","Hani"," "," ",
"Idriss","Imed","Ismail"," ",
"Jabir"," "," "," ",
"Kader","Kamel","Karim","Khaled","Khalill"," "," "," ",
"Lotfi"," ", " ", " ",
"Mahboub","Mahfoud","Mahmoud","Malik","Mourad"," ", " ", " ",
"Nabil","Nacer","Nadjib","Nassim","Nazim"," ", " ", " ",
"Omar","Othmane","Oussama", " ",
"Rachid","Ramzi","Raouf","Rayan","Reda"," ", " ", " ",
"Sabri","Salim","Sami", " ",
"Taoufik"," "," ", " ",
"Walid","Waiil","Wassim","Wafid",
"Yacine"," "," ", " ",
"Zahi","Zakaria","Zoubair", " ",};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prenom_garc);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
b_back =(Button) findViewById(R.id.b_back);
b_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PrenomGarcActivity.this.finish();
}
});
gridview = (GridView) findViewById(R.id.grid_view);
Typeface custom_font= Typeface.createFromAsset(getAssets(), "fonts/tgr.otf");
if(findViewById(R.id.prenomgarc).getTag().equals("med_screen")) {
GridAdapter adapter = new GridAdapter(this, names, custom_font);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if (!names[position].equals(" ")) {
Intent intent = new Intent(PrenomGarcActivity.this, PrenomSpecActivity.class);
intent.putExtra("nom", names[position]);
intent.putExtra("sexe", "g");
startActivity(intent);
}
}
});
}else{
GridAdapter adapter = new GridAdapter(this, namesBigScreen, custom_font);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if (!namesBigScreen[position].equals(" ")) {
Intent intent = new Intent(PrenomGarcActivity.this, PrenomSpecActivity.class);
intent.putExtra("nom", namesBigScreen[position]);
intent.putExtra("sexe", "g");
startActivity(intent);
}
}
});
}
}
private int getscroll(String s){
for (int i = 0; i <names.length; i++){
if (names[i].substring(0,1).toLowerCase().equals(s))
return i;
}
return 100;
}
}